QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#463633#7304. Coins 2hos_lyricWA 58ms12980kbC++144.0kb2024-07-05 08:52:312024-07-05 08:52:32

Judging History

你现在查看的是最新测评结果

  • [2024-07-05 08:52:32]
  • 评测
  • 测评结果:WA
  • 用时:58ms
  • 内存:12980kb
  • [2024-07-05 08:52:31]
  • 提交

answer

#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

using Int = long long;

template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
#define COLOR(s) ("\x1b[" s "m")


// N^2
constexpr int MAX = 310;

int N;
vector<Int> A;

int main() {
  for (; ~scanf("%d", &N); ) {
    A.assign(N + 1, 0);
    for (int i = 1; i <= N; ++i) {
      scanf("%lld", &A[i]);
    }
    
    int L = 1;
    for (int i = 1; i <= N; ++i) {
      L = L / __gcd(L, i) * i;
    }
    
    vector<Int> sufBase(N + 2, 0);
    vector<bitset<MAX>> pre(N + 2), suf(N + 2);
    pre[0].set(0);
    for (int i = 1; i <= N; ++i) {
      for (Int b = 0; b <= A[i] && b <= N; ++b) {
        pre[i] |= pre[i - 1] << (b * i);
      }
    }
    suf[N + 1].set(0);
    for (int i = N; i >= 1; --i) {
      sufBase[i] = A[i] * i + sufBase[i + 1];
      for (Int b = 0; b <= A[i] && b <= N; ++b) {
        suf[i] |= suf[i + 1] << (b * i);
      }
    }
    
    Int ans = 0;
    vector<Int> hard;
    for (int y = 0; y <= N*N; ++y) if (suf[1][y]) {
      hard.push_back(sufBase[1] - y);
    }
    for (int i = 1; i <= N; ++i) {
      /*
        i: max i s.t. b[i] <= A[i] - (i-1)
        pre[i-1] + [0, A[i] - (i-1)] i + (sufBase[i+1] - suf[i+1])
        easy: [sufBase[i+1] + (~ N^2), sufBase[i] - (~ N^2)]
      */
      const Int l = sufBase[i+1] + 2 * N*N;
      const Int r = sufBase[i] - 2 * N*N;
// cerr<<"i = "<<i<<": [l, r] = ["<<l<<", "<<r<<"], help "<<(sufBase[i+1]-N*N)<<" "<<(N*N+A[i]*i+sufBase[i+1])<<endl;
      vector<vector<pair<Int, Int>>> pss(i);
      for (int x = -N*N; x <= N*N; ++x) {
        bool ok = false;
        for (int y = 0; y <= N*N; ++y) if (0 <= x + y && x + y <= N*N) {
          if (pre[i - 1][x + y] && suf[i + 1][y]) {
            ok = true;
            break;
          }
        }
        if (ok) {
          Int b = 0, c = A[i] - (i-1);
          for (Int z; b <= c && (z = x + b * i + sufBase[i+1]) < l; ++b) hard.push_back(z);
          for (Int z; b <= c && (z = x + c * i + sufBase[i+1]) > r; --c) hard.push_back(z);
          if (b <= c) {
            const Int base = x + sufBase[i+1];
            pss[base % i].emplace_back(base / i + b, base / i + c);
          }
        }
      }
      for (int x = 0; x < i; ++x) {
        sort(pss[x].begin(), pss[x].end());
// cerr<<"easy "<<x<<" + "<<pss[x]<<" "<<i<<endl;
// cerr<<i<<" "<<x<<": "<<pss[x].size()<<endl;
        pair<Int, Int> p(-1, -2);
        for (const auto &q : pss[x]) {
          if (p.second < q.first) {
            ans += (p.second - p.first + 1);
            p = q;
          } else {
            chmax(p.second, q.second);
          }
        }
        ans += (p.second - p.first + 1);
      }
    }
cerr<<"|hard| = "<<hard.size()<<endl;
    
    sort(hard.begin(), hard.end());
    hard.erase(unique(hard.begin(), hard.end()), hard.end());
// cerr<<"hard = "<<hard<<endl;
    ans += (int)hard.size();
    printf("%lld\n", ans);
  }
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3820kb

input:

3
0 1 2
3
0 2 3

output:

6
12

result:

ok 2 number(s): "6 12"

Test #2:

score: 0
Accepted
time: 31ms
memory: 12980kb

input:

1
0
15
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000

output:

1
120000000001

result:

ok 2 number(s): "1 120000000001"

Test #3:

score: 0
Accepted
time: 2ms
memory: 4180kb

input:

5
0 2 1 0 0
5
0 0 0 0 53
5
0 6 3 0 0
5
1 0 0 0 1
5
1 0 0 0 0
5
2 0 0 0 116
5
2 0 0 0 0
5
1 0 1 106 1356
5
0 2 0 0 7926
5
0 0 2 1 2004
5
1 0 0 0 1
5
0 0 0 1 5
5
0 0 0 0 0
5
0 1 32840 0 1
5
2 0 0 0 12
5
2 0 0 1 1
5
0 1 79 56770 10
5
1 0 0 1 0
5
0 1 1 2 52165
5
0 0 0 0 1
5
0 0 1 13 0
5
0 0 0 1 10
5
0 0...

output:

6
54
20
4
2
351
3
7207
23781
10027
4
12
1
98524
39
10
227368
4
260837
2
28
22
114
78
76
4
280
233
8
1
12
214572
10
2
1
1
2
108
17760
15926
250077
55576
4
104
282
45419
1687
2973
8
28482
6
4
2988
8
10
102
4
793
69
2
7624
4
181850
84
36589
3
2832
11
25
2
32457
127
33099
2
3
8
116
4
6
260
4
6
29027
4
2...

result:

ok 100 numbers

Test #4:

score: 0
Accepted
time: 0ms
memory: 3940kb

input:

5
0 0 0 0 7282
5
1 0 1 1 1
5
0 100 1 6466 131627995
5
2 0 0 0 1
5
2 0 0 0 0
5
0 0 0 0 2
5
3 0 0 0 24
5
1 0 0 0 0
5
2 0 0 1033661 1
5
2 0 0 0 1
5
1 0 2 1 0
5
1 0 0 74999942 1
5
0 0 16 5 1
5
0 0 14 1 1
5
0 0 0 94148 2
5
1 0 0 0 0
5
0 4 66108 1 1
5
0 0 0 1 0
5
0 2 0 0 0
5
0 0 26609277 2057266 32110772
...

output:

7283
12
658166041
6
3
3
100
2
4134650
6
10
224999830
70
48
282447
2
198340
2
3
248610752
3064
6608762
27104217
88460
1225544
2128
206314
4247620
4756202
2
43189704
4
23417
1151
10
174058
1073133147
4852
2
2
10
77870412
6
13616297
6040750
624815262
1854
300636553
1
4
6
31145401
935098
6
82785138
132
...

result:

ok 100 numbers

Test #5:

score: -100
Wrong Answer
time: 58ms
memory: 4896kb

input:

10
0 0 0 133395012 1 64 1 1 1 29
10
1 0 0 2871 869717 68 15569 112946 431 0
10
2 0 0 0 0 0 0 0 1 1
10
1 0 0 0 0 0 1 1 1 1
10
0 0 0 0 0 0 0 0 0 1
10
0 208 3 0 60131558 184254 1 909 166293 1
10
1 0 0 0 0 0 0 0 0 24784
10
1 0 0 0 1 1 1 26206816 1 0
10
4 0 0 0 0 62468533 1052 0 0 27715813
10
0 0 0 0 0 0...

output:

533580746
5376905
10
20
2
303267664
49570
209654551
651976695
111
9859639
4237554
3045713
509037116
305067
6
25
1852794
2398551872
1651057262
22708645
245970222
110782837
385654273
724791161
56
4
663
100200177
44102430
1298591
9
110583641
7717333
20
612738350
455682
2857417747
135486
4
1103222425
35...

result:

wrong answer 12th numbers differ - expected: '4237557', found: '4237554'