QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#463632 | #7304. Coins 2 | hos_lyric | TL | 0ms | 4088kb | C++14 | 3.8kb | 2024-07-05 08:45:43 | 2024-07-05 08:45:44 |
Judging History
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<<"]"<<endl;
vector<vector<pair<Int, Int>>> pss(i);
for (int x = 0; x <= N*N; ++x) if (pre[i - 1][x]) {
for (int y = 0; y <= N*N; ++y) if (suf[i + 1][y]) {
Int b = 0, c = A[i] - (i-1);
// if(b<=c)cerr<<" can ["<<(x+b*i+(sufBase[i+1]-y))<<", "<<(y+c*i+(sufBase[i+1]-y))<<"]"<<endl;
for (Int z; b <= c && (z = x + b * i + (sufBase[i+1] - y)) < l; ++b) hard.push_back(z);
for (Int z; b <= c && (z = x + c * i + (sufBase[i+1] - y)) > r; --c) hard.push_back(z);
if (b <= c) {
const Int base = x + (sufBase[i+1] - y);
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: 4088kb
input:
3 0 1 2 3 0 2 3
output:
6 12
result:
ok 2 number(s): "6 12"
Test #2:
score: -100
Time Limit Exceeded
input:
1 0 15 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000