Submission #995731


Source Code Expand

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

typedef long double ld;
typedef long long ll;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define pb push_back
#define mp make_pair
#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const ld eps = 1e-9;
const ld pi = acos((ld) -1);

mt19937 mrand(random_device{} ()); 

int rnd(int x) {
  return mrand() % x;
}

void precalc() {
}

const int maxn = (int) 2e4 + 5, logx = 18;
int n;
long long a[maxn];

int read() {
  if (scanf("%d", &n) < 1) {
    return false;
  }
  for (int i = 0; i < n; i++) {
    scanf("%lld", &a[i]);
  }
  return true;
}

long long p10;

vector< pair<long long, long long> > shift(const vector< pair<long long, long long> > &segs, long long sh) {
  vector< pair<long long, long long> > res;
  for (int i = 0; i < sz(segs); i++) {
    long long l = segs[i].first + sh, r = segs[i].second + sh;
    if (r <= p10) {
      res.push_back(make_pair(l, r));
    } else if (l >= p10) {
      l -= p10;
      r -= p10;
      res.push_back(make_pair(l, r));
    } else {
      res.push_back(make_pair(l, p10));
      res.push_back(make_pair(0, r - p10));
    }
  }
  sort(res.begin(), res.end());
  return res;
}

vector< pair<long long, long long> > mergeSegs(const vector< pair<long long, long long> > &a,
                                               const vector< pair<long long, long long> > &b) {
  vector< pair<long long, long long> > res;
  vector< pair<long long, int> > ev;
  for (int i = 0; i < sz(a); i++) {
    ev.push_back(make_pair(a[i].first, -1));
    ev.push_back(make_pair(a[i].second, 1));
  }
  for (int i = 0; i < sz(b); i++) {
    ev.push_back(make_pair(b[i].first, -1));
    ev.push_back(make_pair(b[i].second, 1));
  }
  sort(ev.begin(), ev.end());
  long long l = -1;
  int bal = 0;
  for (int i = 0; i < sz(ev); i++) {
    if (!bal) {
      l = ev[i].first;
    }
    bal -= ev[i].second;
    if (!bal) {
      res.push_back(make_pair(l, ev[i].first));
    }
  }
  return res;
}

void solve() {
  p10 = 1;
  for (int i = 0; i < logx; i++) {
    p10 *= 10;
  }
  int res = 0;
  for (int dig = logx; dig > 0; dig--) {
    for (int i = 0; i < n; i++) {
      a[i] %= p10;
    }
    long long len = p10 / 10;
    for (int x = 9; x >= 0; x--) {
      vector< pair<long long, long long> > segs;
      segs.push_back(make_pair(x * len, (x + 1) * len));
      for (int i = 0; i < n; i++) {
        auto segs0 = shift(segs, (p10 - a[i]) % p10);
        segs = mergeSegs(segs, segs0);
      }
      if (segs[0].first == 0) {
        res += x;
        break;
      }
    }
    p10 /= 10;
  }
  printf("%d\n", res);
}

int main() {
  precalc();
#ifdef LOCAL
  assert(freopen(TASK ".in", "r", stdin));
  assert(freopen(TASK ".out", "w", stdout));
#endif
  while (true) {
    if (!read()) {
      break;
    }
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}

Submission Info

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

Compile Error

./Main.cpp: In function ‘int read()’:
./Main.cpp:45:25: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%lld", &a[i]);
                         ^

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 2 ms 256 KB
01-02.txt AC 2 ms 256 KB
01-03.txt AC 2 ms 256 KB
01-04.txt AC 2 ms 256 KB
01-05.txt AC 3 ms 256 KB
01-06.txt AC 257 ms 384 KB
01-07.txt AC 285 ms 384 KB
01-08.txt AC 292 ms 384 KB
01-09.txt AC 295 ms 384 KB
01-10.txt AC 435 ms 384 KB
01-11.txt AC 410 ms 384 KB
01-12.txt AC 294 ms 384 KB
01-13.txt AC 274 ms 384 KB
01-14.txt AC 250 ms 384 KB
01-15.txt AC 296 ms 384 KB
01-16.txt AC 332 ms 384 KB
01-17.txt AC 296 ms 384 KB
01-18.txt AC 291 ms 384 KB
01-19.txt AC 286 ms 384 KB
01-20.txt AC 270 ms 384 KB
01-21.txt AC 253 ms 384 KB
01-22.txt AC 255 ms 384 KB
01-23.txt AC 268 ms 384 KB
01-24.txt AC 276 ms 384 KB
01-25.txt AC 280 ms 384 KB
01-26.txt AC 278 ms 384 KB
01-27.txt AC 271 ms 384 KB
01-28.txt AC 255 ms 384 KB
01-29.txt AC 273 ms 384 KB
01-30.txt AC 256 ms 384 KB
01-31.txt AC 256 ms 384 KB
01-32.txt AC 287 ms 384 KB
01-33.txt AC 289 ms 384 KB
01-34.txt AC 252 ms 384 KB
01-35.txt AC 259 ms 384 KB
01-36.txt AC 281 ms 384 KB
01-37.txt AC 260 ms 384 KB
01-38.txt AC 255 ms 384 KB
01-39.txt AC 254 ms 384 KB
01-40.txt AC 262 ms 384 KB
01-41.txt AC 270 ms 384 KB
01-42.txt AC 256 ms 384 KB
01-43.txt AC 254 ms 384 KB
01-44.txt AC 267 ms 384 KB
01-45.txt AC 252 ms 384 KB
01-46.txt AC 267 ms 384 KB
01-47.txt AC 279 ms 384 KB
01-48.txt AC 265 ms 384 KB
01-49.txt AC 265 ms 384 KB
01-50.txt AC 258 ms 384 KB
01-51.txt AC 259 ms 384 KB
01-52.txt AC 266 ms 384 KB
01-53.txt AC 266 ms 384 KB
01-54.txt AC 271 ms 384 KB
01-55.txt AC 255 ms 384 KB
01-56.txt AC 258 ms 384 KB
01-57.txt AC 257 ms 384 KB
01-58.txt AC 260 ms 384 KB
01-59.txt AC 256 ms 384 KB
01-60.txt AC 254 ms 384 KB
01-61.txt AC 256 ms 384 KB
01-62.txt AC 254 ms 384 KB
01-63.txt AC 257 ms 384 KB
01-64.txt AC 257 ms 384 KB
01-65.txt AC 251 ms 384 KB
01-66.txt AC 703 ms 384 KB
01-67.txt AC 355 ms 384 KB
01-68.txt AC 307 ms 384 KB
01-69.txt AC 302 ms 384 KB
01-70.txt AC 281 ms 384 KB
01-71.txt AC 518 ms 384 KB
01-72.txt AC 502 ms 384 KB
01-73.txt AC 543 ms 384 KB
01-74.txt AC 637 ms 384 KB
01-75.txt AC 592 ms 384 KB
01-76.txt AC 728 ms 384 KB
01-77.txt AC 290 ms 384 KB
01-78.txt AC 481 ms 384 KB
01-79.txt AC 425 ms 384 KB
01-80.txt AC 459 ms 384 KB
01-81.txt AC 464 ms 384 KB
01-82.txt AC 467 ms 384 KB
01-83.txt AC 520 ms 384 KB
01-84.txt AC 540 ms 384 KB
01-85.txt AC 517 ms 384 KB
01-86.txt AC 580 ms 384 KB
01-87.txt AC 567 ms 384 KB
01-88.txt AC 573 ms 384 KB
01-89.txt AC 563 ms 384 KB
01-90.txt AC 251 ms 384 KB
01-91.txt AC 418 ms 384 KB
01-92.txt AC 494 ms 384 KB
01-93.txt AC 486 ms 384 KB
01-94.txt AC 428 ms 384 KB
01-95.txt AC 439 ms 512 KB
01-96.txt AC 253 ms 384 KB
01-97.txt AC 433 ms 384 KB
01-98.txt AC 442 ms 384 KB
sample-01.txt AC 3 ms 256 KB
sample-02.txt AC 2 ms 256 KB