QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#463617#7304. Coins 2hos_lyricWA 1ms4088kbC++143.2kb2024-07-05 06:56:392024-07-05 06:56:39

Judging History

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

  • [2024-07-05 06:56:39]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:4088kb
  • [2024-07-05 06:56:39]
  • 提交

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")


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<bitset<310>> pre(N + 1);
    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);
      }
    }
    
    vector<Int> suf(N + 2, 0);
    for (int i = N; i >= 1; --i) {
      suf[i] = A[i] * i + suf[i + 1];
    }
    
    Int ans = 0;
    vector<Int> hard{suf[1]};
    for (int i = 1; i <= N; ++i) {
      /*
        i: max non-full
        pre[0, (i-1)^2] + [0, A[i]-1] i + suf[i+1]
        easy: [suf[i+1] + i^2, suf[i])
      */
      const Int l = suf[i+1] + i*i;
      const Int r = suf[i] - 1;
      vector<vector<pair<Int, Int>>> pss(i);
      for (int x = 0; x <= (i-1)*(i-1); ++x) if (pre[i - 1][x]) {
        Int b = 0, c = A[i] - 1;
        for (Int y; b <= c && (y = x + b * i + suf[i+1]) < l; ++b) hard.push_back(y);
        for (Int y; b <= c && (y = x + c * i + suf[i+1]) > r; --c) hard.push_back(y);
        if (b <= c) {
          const Int base = x + suf[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;
        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);
      }
    }
    
    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: 3828kb

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: 1ms
memory: 3964kb

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: -100
Wrong Answer
time: 1ms
memory: 4088kb

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
16
4
2
351
3
7104
23781
10027
4
12
1
65690
39
10
227291
4
260837
2
28
22
114
78
76
4
192
124
8
1
12
157892
10
2
1
1
2
108
17760
15926
246807
45512
4
104
282
43516
1521
2973
8
27959
6
4
2988
8
10
102
4
652
69
2
7624
4
121238
84
29746
3
2832
11
25
2
32457
127
25093
2
3
8
85
4
6
260
4
6
29030
4
2
...

result:

wrong answer 3rd numbers differ - expected: '20', found: '16'