Submission #1023187


Source Code Expand

#include <iostream>
#include <vector>
#include <algorithm>
#include <cassert>
#define repeat(i,n) for (int i = 0; (i) < int(n); ++(i))
#define repeat_from_reverse(i,m,n) for (int i = (n)-1; (i) >= int(m); --(i))
#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
typedef long long ll;
using namespace std;
struct interval_t { ll l, r; };
bool operator < (interval_t a, interval_t b) { return make_pair(a.l, a.r) < make_pair(b.l, b.r); }
bool is_mergeable(interval_t a, interval_t b) { return not (a.r <= b.l or b.r <= a.l); }
interval_t merge(interval_t a, interval_t b) { assert (is_mergeable(a, b)); return { min(a.l, b.l), max(a.r, b.r) }; }
interval_t shift(interval_t a, ll b) { return { a.l - b, a.r - b }; }
interval_t adjust(interval_t a, ll b) { ll l = (a.l % b + b) % b; return { l, a.r + (l - a.l) }; }
bool does_include(interval_t a, ll b) { return a.l <= b and b < a.r; }
int main() {
    int n; cin >> n;
    vector<ll> as(n); repeat (i,n) cin >> as[i];
    int ans = 0;
    for (ll e = 1; e <= ll(1e17); e *= 10) {
        repeat_from_reverse (d,1,10) {
            vector<interval_t> xs;
            xs.push_back({ d*e, (d+1)*e });
            for (ll a : as) {
                vector<interval_t> ys = xs;
                for (interval_t x : xs) {
                    ys.push_back(       shift(x, a % (10*e)));
                    ys.push_back(adjust(shift(x, a % (10*e)), 10*e));
                }
                xs.clear();
                whole(sort, ys);
                for (interval_t y : ys) {
                    if (y.r <= 0) continue;
                    if (xs.empty() or not is_mergeable(xs.back(), y)) {
                        xs.push_back(y);
                    } else {
                        xs.back() = merge(xs.back(), y);
                    }
                }
            }
            bool found = false;
            for (interval_t x : xs) {
                if (does_include(x, 0)) {
                    found = true;
                }
            }
            if (found) {
                ans += d;
                break;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Submission Info

Submission Time
Task B - Exact Payment
User kimiyuki
Language C++14 (GCC 5.4.1)
Score 1500
Code Size 2254 Byte
Status AC
Exec Time 487 ms
Memory 512 KB

Judge Result

Set Name sample All
Score / Max Score 0 / 0 1500 / 1500
Status
AC × 2
AC × 100
Set Name Test Cases
sample sample-01.txt, sample-02.txt
All sample-01.txt, sample-02.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt, 01-17.txt, 01-18.txt, 01-19.txt, 01-20.txt, 01-21.txt, 01-22.txt, 01-23.txt, 01-24.txt, 01-25.txt, 01-26.txt, 01-27.txt, 01-28.txt, 01-29.txt, 01-30.txt, 01-31.txt, 01-32.txt, 01-33.txt, 01-34.txt, 01-35.txt, 01-36.txt, 01-37.txt, 01-38.txt, 01-39.txt, 01-40.txt, 01-41.txt, 01-42.txt, 01-43.txt, 01-44.txt, 01-45.txt, 01-46.txt, 01-47.txt, 01-48.txt, 01-49.txt, 01-50.txt, 01-51.txt, 01-52.txt, 01-53.txt, 01-54.txt, 01-55.txt, 01-56.txt, 01-57.txt, 01-58.txt, 01-59.txt, 01-60.txt, 01-61.txt, 01-62.txt, 01-63.txt, 01-64.txt, 01-65.txt, 01-66.txt, 01-67.txt, 01-68.txt, 01-69.txt, 01-70.txt, 01-71.txt, 01-72.txt, 01-73.txt, 01-74.txt, 01-75.txt, 01-76.txt, 01-77.txt, 01-78.txt, 01-79.txt, 01-80.txt, 01-81.txt, 01-82.txt, 01-83.txt, 01-84.txt, 01-85.txt, 01-86.txt, 01-87.txt, 01-88.txt, 01-89.txt, 01-90.txt, 01-91.txt, 01-92.txt, 01-93.txt, 01-94.txt, 01-95.txt, 01-96.txt, 01-97.txt, 01-98.txt
Case Name Status Exec Time Memory
01-01.txt AC 3 ms 256 KB
01-02.txt AC 2 ms 256 KB
01-03.txt AC 3 ms 256 KB
01-04.txt AC 3 ms 256 KB
01-05.txt AC 3 ms 256 KB
01-06.txt AC 151 ms 384 KB
01-07.txt AC 148 ms 384 KB
01-08.txt AC 163 ms 384 KB
01-09.txt AC 184 ms 384 KB
01-10.txt AC 262 ms 384 KB
01-11.txt AC 249 ms 384 KB
01-12.txt AC 158 ms 512 KB
01-13.txt AC 159 ms 384 KB
01-14.txt AC 155 ms 384 KB
01-15.txt AC 156 ms 384 KB
01-16.txt AC 197 ms 384 KB
01-17.txt AC 166 ms 384 KB
01-18.txt AC 165 ms 384 KB
01-19.txt AC 168 ms 384 KB
01-20.txt AC 169 ms 384 KB
01-21.txt AC 166 ms 384 KB
01-22.txt AC 161 ms 384 KB
01-23.txt AC 159 ms 384 KB
01-24.txt AC 177 ms 384 KB
01-25.txt AC 169 ms 384 KB
01-26.txt AC 180 ms 512 KB
01-27.txt AC 155 ms 384 KB
01-28.txt AC 160 ms 384 KB
01-29.txt AC 178 ms 384 KB
01-30.txt AC 152 ms 384 KB
01-31.txt AC 152 ms 384 KB
01-32.txt AC 168 ms 384 KB
01-33.txt AC 170 ms 384 KB
01-34.txt AC 158 ms 384 KB
01-35.txt AC 152 ms 384 KB
01-36.txt AC 176 ms 384 KB
01-37.txt AC 151 ms 384 KB
01-38.txt AC 184 ms 384 KB
01-39.txt AC 166 ms 384 KB
01-40.txt AC 166 ms 384 KB
01-41.txt AC 159 ms 384 KB
01-42.txt AC 157 ms 384 KB
01-43.txt AC 152 ms 384 KB
01-44.txt AC 149 ms 384 KB
01-45.txt AC 156 ms 384 KB
01-46.txt AC 164 ms 384 KB
01-47.txt AC 164 ms 384 KB
01-48.txt AC 173 ms 384 KB
01-49.txt AC 167 ms 384 KB
01-50.txt AC 153 ms 384 KB
01-51.txt AC 153 ms 384 KB
01-52.txt AC 164 ms 384 KB
01-53.txt AC 164 ms 384 KB
01-54.txt AC 174 ms 384 KB
01-55.txt AC 159 ms 384 KB
01-56.txt AC 159 ms 384 KB
01-57.txt AC 160 ms 384 KB
01-58.txt AC 156 ms 384 KB
01-59.txt AC 166 ms 384 KB
01-60.txt AC 158 ms 384 KB
01-61.txt AC 167 ms 384 KB
01-62.txt AC 151 ms 384 KB
01-63.txt AC 157 ms 384 KB
01-64.txt AC 158 ms 384 KB
01-65.txt AC 158 ms 384 KB
01-66.txt AC 487 ms 384 KB
01-67.txt AC 251 ms 384 KB
01-68.txt AC 256 ms 384 KB
01-69.txt AC 214 ms 384 KB
01-70.txt AC 196 ms 384 KB
01-71.txt AC 349 ms 384 KB
01-72.txt AC 326 ms 384 KB
01-73.txt AC 387 ms 384 KB
01-74.txt AC 444 ms 384 KB
01-75.txt AC 425 ms 384 KB
01-76.txt AC 487 ms 384 KB
01-77.txt AC 192 ms 384 KB
01-78.txt AC 325 ms 384 KB
01-79.txt AC 302 ms 384 KB
01-80.txt AC 322 ms 384 KB
01-81.txt AC 327 ms 384 KB
01-82.txt AC 323 ms 384 KB
01-83.txt AC 358 ms 384 KB
01-84.txt AC 374 ms 384 KB
01-85.txt AC 345 ms 384 KB
01-86.txt AC 362 ms 384 KB
01-87.txt AC 381 ms 384 KB
01-88.txt AC 376 ms 384 KB
01-89.txt AC 348 ms 384 KB
01-90.txt AC 166 ms 384 KB
01-91.txt AC 283 ms 384 KB
01-92.txt AC 316 ms 384 KB
01-93.txt AC 312 ms 384 KB
01-94.txt AC 293 ms 384 KB
01-95.txt AC 302 ms 384 KB
01-96.txt AC 164 ms 384 KB
01-97.txt AC 289 ms 384 KB
01-98.txt AC 297 ms 384 KB
sample-01.txt AC 3 ms 256 KB
sample-02.txt AC 3 ms 256 KB