QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#275554 | #7257. Paint | PetroTarnavskyi# | WA | 1ms | 3920kb | C++20 | 3.1kb | 2023-12-04 20:29:19 | 2023-12-04 20:29:20 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); i--)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second
typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;
const int mod = 1e9 + 7;
void updAdd(int& a, int b)
{
a += b;
if(a >= mod)
a -= mod;
}
void updSub(int& a, int b)
{
a -= b;
if(a < 0)
a += mod;
}
int mult(int a, int b)
{
return (LL)a * b % mod;
}
int binpow(int a, int n)
{
int res = 1;
while(n)
{
if(n & 1)
res = mult(res, a);
a = mult(a, a);
n /= 2;
}
return res;
}
int inv(int x)
{
return binpow(x, mod - 2);
}
int C(int n, int m)
{
int ans = 1;
FOR(i, 0, m)
{
ans = mult(ans, n - i);
ans = mult(ans, inv(i + 1));
}
return ans;
}
int solve(int n, VI lens)
{
n -= SZ(lens) - 1;
FOR(i, 0, SZ(lens))
n -= lens[i];
if(n < 0)
return 0;
int cnt = 2 * SZ(lens) + 1;
return C(n + cnt - 1, cnt - 1);
}
set<vector<PII>> calculated;
int solve(int n, vector<PII> lens)
{
if(calculated.count(lens) == 1)
return 0;
calculated.insert(lens);
int ans = 0;
FOR(mask, 0, 1 << SZ(lens))
{
VI cur(SZ(lens));
FOR(i, 0, SZ(lens))
{
if((mask >> i) & 1)
cur[i] = lens[i].S;
else
cur[i] = lens[i].F;
}
int val = solve(n, cur);
if(__builtin_popcount(mask) % 2 == 0)
updAdd(ans, val);
else
updSub(ans, val);
}
return ans;
}
vector<PII> possible[4];
vector<PII> genVec;
int resRecalc = 0;
void rec(int pos, int sz, int n)
{
if(pos == sz)
{
updAdd(resRecalc, solve(n, genVec));
return;
}
for(auto val : possible[pos])
{
genVec.PB(val);
rec(pos + 1, sz, n);
genVec.pop_back();
}
}
VI vals;
int recalc(int n, vector<PII> lens)
{
resRecalc = 0;
FOR(i, 0, SZ(lens))
{
possible[i].clear();
int prev = lens[i].F;
FOR(j, 0, SZ(vals))
{
if(vals[j] <= prev)
continue;
possible[i].PB(MP(prev, vals[j]));
prev = vals[j];
if(vals[j] == lens[i].S)
break;
}
}
rec(0, SZ(lens), n);
return resRecalc;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout << fixed << setprecision(15);
int n, k;
cin >> n >> k;
VI a(k);
FOR(i, 0, k)
cin >> a[i];
FOR(mask, 1, 1 << k)
{
int sum = 0;
FOR(i, 0, k)
if((mask >> i) & 1)
sum += a[i];
vals.PB(sum);
vals.PB(sum + 1);
}
sort(ALL(vals));
int ans = 0;
VI idx(k);
iota(ALL(idx), 0);
do{
FOR(mask, 0, 1 << (k - 1))
{
vector<PII> lens = {MP(a[idx[0]], a[idx[0]] + 1)};
FOR(i, 0, k - 1)
{
if((mask >> i) & 1)
{
lens.back().F = max(lens.back().F, a[idx[i + 1]]);
lens.back().S += a[idx[i + 1]];
}
else
lens.PB(MP(a[idx[i + 1]], a[idx[i + 1]] + 1));
}
updAdd(ans, recalc(n, lens));
}
}while(next_permutation(ALL(idx)));
cout << ans << endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3604kb
input:
10 2 1 1
output:
55
result:
ok 1 number(s): "55"
Test #2:
score: 0
Accepted
time: 1ms
memory: 3652kb
input:
1000000000 4 2015 2015 123456789 27
output:
782767239
result:
ok 1 number(s): "782767239"
Test #3:
score: 0
Accepted
time: 1ms
memory: 3608kb
input:
1000000000 4 158260522 877914575 602436426 24979445
output:
660970994
result:
ok 1 number(s): "660970994"
Test #4:
score: 0
Accepted
time: 1ms
memory: 3636kb
input:
1000000000 4 861648772 623690081 433933447 476190629
output:
285087118
result:
ok 1 number(s): "285087118"
Test #5:
score: 0
Accepted
time: 1ms
memory: 3648kb
input:
1000000000 4 262703497 211047202 971407775 628894325
output:
705252352
result:
ok 1 number(s): "705252352"
Test #6:
score: 0
Accepted
time: 1ms
memory: 3632kb
input:
1000000000 4 731963982 822804784 450968417 430302156
output:
442542649
result:
ok 1 number(s): "442542649"
Test #7:
score: 0
Accepted
time: 1ms
memory: 3696kb
input:
1000000000 4 982631932 161735902 880895728 923078537
output:
918022647
result:
ok 1 number(s): "918022647"
Test #8:
score: 0
Accepted
time: 1ms
memory: 3644kb
input:
1000000000 4 707723857 189330739 910286918 802329211
output:
647369460
result:
ok 1 number(s): "647369460"
Test #9:
score: 0
Accepted
time: 1ms
memory: 3920kb
input:
1000000000 4 404539679 303238506 317063340 492686568
output:
212860747
result:
ok 1 number(s): "212860747"
Test #10:
score: 0
Accepted
time: 1ms
memory: 3912kb
input:
1000000000 4 773361868 125660016 650287940 839296263
output:
89880693
result:
ok 1 number(s): "89880693"
Test #11:
score: 0
Accepted
time: 1ms
memory: 3632kb
input:
1000000000 4 462224593 492601449 384836991 191890310
output:
650499095
result:
ok 1 number(s): "650499095"
Test #12:
score: 0
Accepted
time: 1ms
memory: 3636kb
input:
1000000000 4 576823355 782177068 404011431 818008580
output:
633872265
result:
ok 1 number(s): "633872265"
Test #13:
score: 0
Accepted
time: 0ms
memory: 3628kb
input:
1000000000 4 954291757 160449218 155374934 840594328
output:
800323543
result:
ok 1 number(s): "800323543"
Test #14:
score: 0
Accepted
time: 1ms
memory: 3704kb
input:
1000000000 4 164163676 797829355 138996221 501899080
output:
107066835
result:
ok 1 number(s): "107066835"
Test #15:
score: 0
Accepted
time: 1ms
memory: 3612kb
input:
1000000000 4 353195922 545531545 910748511 350034067
output:
250355397
result:
ok 1 number(s): "250355397"
Test #16:
score: 0
Accepted
time: 1ms
memory: 3696kb
input:
1000000000 4 913575467 470338674 824284691 533206504
output:
55628645
result:
ok 1 number(s): "55628645"
Test #17:
score: 0
Accepted
time: 1ms
memory: 3668kb
input:
1000000000 4 180999835 31262034 138344965 677959980
output:
742514685
result:
ok 1 number(s): "742514685"
Test #18:
score: 0
Accepted
time: 0ms
memory: 3548kb
input:
1000000000 4 131381221 846045895 208032501 346948152
output:
140767748
result:
ok 1 number(s): "140767748"
Test #19:
score: -100
Wrong Answer
time: 0ms
memory: 3572kb
input:
1000000000 4 973708325 506147731 893229302 816248153
output:
929601937
result:
wrong answer 1st numbers differ - expected: '124170944', found: '929601937'