Submission #995680


Source Code Expand

#include <bits/stdc++.h>

using namespace std;

const int N = 1234567;

long long a[N], s[N], b[N];
int ans[42];

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%lld", a + i);
  }
  long long step = 1;
  for (int dig = 0; dig < 17; dig++) {
    step *= 10;
    for (int i = 0; i < n; i++) {
      b[i] = a[i] % step;
    }
    sort(b, b + n);
    s[0] = 0;
    for (int i = 0; i < n; i++) {
      s[i + 1] = s[i] + b[i];
    }
    set <long long> e;
    e.insert(0LL);
    long long mx = 0;
    for (int i = 1; i <= n; i++) {
      long long cur = s[i] % step;
      auto it = e.lower_bound(cur + 1);
      if (it == e.end()) {
        it = e.begin();
      }
      long long other = *it;
      long long diff = cur - other;
      if (diff < 0) {
        diff += step;
      }
      if (diff > mx) {
        mx = diff;
      }
    }
    ans[dig] = max(ans[dig], (int) (mx / (step / 10)));
  }
  while (true) {
    double T = clock() * 1.0 / CLOCKS_PER_SEC;
    if (T > 1.7) {
      break;
    }
    random_shuffle(a, a + n);
    s[0] = 0;
    for (int i = 0; i < n; i++) {
      s[i + 1] = s[i] + a[i];
    }
    long long step = 1;
    for (int dig = 0; dig < 17; dig++) {
      step *= 10;
      set <long long> e;
      e.insert(0LL);
      long long mx = 0;
      for (int i = 1; i <= n; i++) {
        long long cur = s[i] % step;
        auto it = e.lower_bound(cur + 1);
        if (it == e.end()) {
          it = e.begin();
        }
        long long other = *it;
        long long diff = cur - other;
        if (diff < 0) {
          diff += step;
        }
        if (diff > mx) {
          mx = diff;
        }
      }
      ans[dig] = max(ans[dig], (int) (mx / (step / 10)));
    }
  }
  int res = 0;
  for (int dig = 0; dig < 17; dig++) {
    res += ans[dig];
  }
  printf("%d\n", res);
  return 0;
}

Submission Info

Submission Time
Task B - Exact Payment
User tourist
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1942 Byte
Status WA
Exec Time 1707 ms
Memory 896 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:12:18: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &n);
                  ^
./Main.cpp:14: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 0 / 1500
Status
AC × 2
AC × 87
WA × 13
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 1702 ms 256 KB
01-02.txt AC 1701 ms 256 KB
01-03.txt AC 1701 ms 256 KB
01-04.txt AC 1701 ms 384 KB
01-05.txt AC 1701 ms 256 KB
01-06.txt AC 1705 ms 768 KB
01-07.txt AC 1702 ms 768 KB
01-08.txt AC 1702 ms 896 KB
01-09.txt AC 1702 ms 768 KB
01-10.txt AC 1703 ms 768 KB
01-11.txt AC 1703 ms 768 KB
01-12.txt AC 1703 ms 896 KB
01-13.txt AC 1702 ms 768 KB
01-14.txt AC 1703 ms 768 KB
01-15.txt AC 1701 ms 768 KB
01-16.txt AC 1704 ms 768 KB
01-17.txt AC 1703 ms 768 KB
01-18.txt AC 1703 ms 768 KB
01-19.txt AC 1703 ms 768 KB
01-20.txt AC 1702 ms 768 KB
01-21.txt AC 1705 ms 768 KB
01-22.txt AC 1705 ms 768 KB
01-23.txt AC 1704 ms 768 KB
01-24.txt AC 1703 ms 768 KB
01-25.txt AC 1704 ms 768 KB
01-26.txt AC 1702 ms 768 KB
01-27.txt AC 1701 ms 768 KB
01-28.txt AC 1702 ms 768 KB
01-29.txt AC 1701 ms 768 KB
01-30.txt AC 1703 ms 768 KB
01-31.txt WA 1702 ms 768 KB
01-32.txt WA 1705 ms 768 KB
01-33.txt WA 1701 ms 768 KB
01-34.txt WA 1701 ms 768 KB
01-35.txt WA 1705 ms 768 KB
01-36.txt WA 1705 ms 768 KB
01-37.txt WA 1702 ms 768 KB
01-38.txt WA 1702 ms 768 KB
01-39.txt WA 1704 ms 768 KB
01-40.txt WA 1702 ms 768 KB
01-41.txt WA 1701 ms 896 KB
01-42.txt WA 1704 ms 768 KB
01-43.txt WA 1703 ms 768 KB
01-44.txt AC 1705 ms 768 KB
01-45.txt AC 1701 ms 768 KB
01-46.txt AC 1704 ms 768 KB
01-47.txt AC 1703 ms 768 KB
01-48.txt AC 1703 ms 768 KB
01-49.txt AC 1703 ms 768 KB
01-50.txt AC 1703 ms 896 KB
01-51.txt AC 1703 ms 768 KB
01-52.txt AC 1704 ms 768 KB
01-53.txt AC 1704 ms 768 KB
01-54.txt AC 1707 ms 768 KB
01-55.txt AC 1704 ms 768 KB
01-56.txt AC 1701 ms 768 KB
01-57.txt AC 1704 ms 768 KB
01-58.txt AC 1703 ms 768 KB
01-59.txt AC 1702 ms 768 KB
01-60.txt AC 1702 ms 768 KB
01-61.txt AC 1704 ms 768 KB
01-62.txt AC 1704 ms 896 KB
01-63.txt AC 1702 ms 768 KB
01-64.txt AC 1703 ms 768 KB
01-65.txt AC 1703 ms 768 KB
01-66.txt AC 1702 ms 768 KB
01-67.txt AC 1702 ms 768 KB
01-68.txt AC 1705 ms 768 KB
01-69.txt AC 1704 ms 768 KB
01-70.txt AC 1704 ms 768 KB
01-71.txt AC 1701 ms 768 KB
01-72.txt AC 1702 ms 768 KB
01-73.txt AC 1701 ms 768 KB
01-74.txt AC 1704 ms 768 KB
01-75.txt AC 1705 ms 768 KB
01-76.txt AC 1703 ms 896 KB
01-77.txt AC 1704 ms 896 KB
01-78.txt AC 1703 ms 768 KB
01-79.txt AC 1705 ms 768 KB
01-80.txt AC 1704 ms 768 KB
01-81.txt AC 1703 ms 768 KB
01-82.txt AC 1702 ms 768 KB
01-83.txt AC 1705 ms 768 KB
01-84.txt AC 1702 ms 768 KB
01-85.txt AC 1701 ms 768 KB
01-86.txt AC 1705 ms 768 KB
01-87.txt AC 1704 ms 768 KB
01-88.txt AC 1704 ms 768 KB
01-89.txt AC 1702 ms 768 KB
01-90.txt AC 1703 ms 768 KB
01-91.txt AC 1704 ms 896 KB
01-92.txt AC 1702 ms 768 KB
01-93.txt AC 1701 ms 768 KB
01-94.txt AC 1704 ms 768 KB
01-95.txt AC 1702 ms 768 KB
01-96.txt AC 1703 ms 768 KB
01-97.txt AC 1703 ms 768 KB
01-98.txt AC 1701 ms 768 KB
sample-01.txt AC 1701 ms 256 KB
sample-02.txt AC 1701 ms 256 KB