QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#425523 | #6355. 5 | ushg8877 | TL | 4807ms | 18776kb | C++14 | 1.4kb | 2024-05-30 12:43:29 | 2024-05-30 12:43:29 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define vi vector<array<int,2> >
#define ll long long
const int MAXN=2e5+5;
int n,s,cnt[MAXN];
vi vec[MAXN<<1];
vi operator +(vi a,int x){
vi b;
for(auto i:a) b.push_back({i[0]+x,i[1]+x});
return b;
}
vi merge(vi a,vi b){
if(a.empty()||b.empty()) return a.empty()?b:a;
vi c;
for(auto i:b) a.push_back(i);
sort(a.begin(),a.end());
for(int i=0,j;i<(int)a.size();i++){
int l=a[i][0],r=a[i][1];
j=i;
while(j+1<(int)a.size()&&a[j+1][0]<=r+1){
j++;
r=max(r,a[j][1]);
}
i=j;
c.push_back({l,r});
}
return c;
}
int main(){
ios::sync_with_stdio(false);
// freopen("Otomachi_Una.in","r",stdin);
// freopen("Otomachi_Una.out","w",stdout);
cin>>n>>s;
for(int i=1;i<=n;i++){
int x;cin>>x;
cnt[x]++;
}
vec[MAXN].push_back({0,0});
for(int i=0;i<=s;i++) if(cnt[i]){
auto upd=[&](int x){
if(i==0){
for(int k=-n;k<=s;k++){
int t=k+(i-1)*x;
if(-s<=t&&t<=s) vec[t+MAXN]=merge(vec[t+MAXN],vec[k+MAXN]+x);
}
}else{
for(int k=s;k>=-n;k--){
int t=k+(i-1)*x;
if(-s<=t&&t<=s) vec[t+MAXN]=merge(vec[t+MAXN],vec[k+MAXN]+x);
}
}
};
for(int j=0;j<20;j++) if(cnt[i]>=(1<<j)){
cnt[i]-=(1<<j);
upd(1<<j);
}
if(cnt[i]) upd(cnt[i]);
}
ll ans=0;
for(int i=-n;i<=s;i++) for(auto j:vec[i+MAXN]) ans+=j[1]-j[0]+1;
cout<<ans<<'\n';
cerr<<"Running Time: "<<1.0*clock()/CLOCKS_PER_SEC<<'\n';
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 13252kb
input:
7 9 0 0 0 1 1 2 5
output:
42
result:
ok 1 number(s): "42"
Test #2:
score: 0
Accepted
time: 2ms
memory: 13256kb
input:
10 33 9 9 8 1 1 1 1 1 1 1
output:
48
result:
ok 1 number(s): "48"
Test #3:
score: 0
Accepted
time: 0ms
memory: 13260kb
input:
10 14 2 4 4 1 0 1 0 1 0 1
output:
81
result:
ok 1 number(s): "81"
Test #4:
score: 0
Accepted
time: 3ms
memory: 13256kb
input:
10 14 3 5 3 0 1 0 1 0 1 0
output:
87
result:
ok 1 number(s): "87"
Test #5:
score: 0
Accepted
time: 0ms
memory: 13292kb
input:
40 50 1 1 1 1 3 3 0 3 1 1 0 0 2 1 0 0 1 0 0 2 7 1 2 1 3 0 2 2 3 1 1 0 0 2 0 1 1 0 1 1
output:
1067
result:
ok 1 number(s): "1067"
Test #6:
score: 0
Accepted
time: 5ms
memory: 14200kb
input:
1200 1000 1 1 2 3 0 1 0 0 1 1 0 2 3 0 1 2 0 0 1 0 4 1 1 2 1 1 0 0 1 1 0 1 0 0 1 0 1 0 0 0 1 1 0 1 0 0 1 0 0 1 1 0 1 2 0 4 0 3 1 6 0 1 1 0 0 0 0 4 0 0 0 0 0 0 1 0 0 1 7 1 1 1 0 1 0 1 0 1 1 0 0 1 1 1 3 0 1 0 1 0 0 1 1 2 2 0 1 1 0 0 1 4 1 2 0 0 0 3 0 0 2 1 0 2 0 0 0 1 1 0 0 2 0 0 0 0 1 1 0 1 0 1 6 1 1 ...
output:
737899
result:
ok 1 number(s): "737899"
Test #7:
score: 0
Accepted
time: 56ms
memory: 13644kb
input:
12000 10000 1 1 0 0 1 0 2 1 3 0 0 1 0 3 1 1 0 1 1 1 1 1 2 1 0 1 2 1 0 1 2 0 5 1 1 1 0 2 0 1 0 1 0 3 2 0 1 0 1 1 2 1 0 0 1 1 0 1 0 0 0 1 0 1 0 1 0 4 0 1 3 1 0 0 1 0 1 2 1 0 0 1 1 0 2 1 1 0 1 0 1 0 0 2 1 1 3 0 1 1 1 0 0 0 1 1 1 0 3 0 0 0 2 0 0 0 1 0 2 0 1 1 1 0 0 1 0 1 0 2 0 0 0 0 0 0 0 1 0 1 0 0 4 1 ...
output:
73685347
result:
ok 1 number(s): "73685347"
Test #8:
score: 0
Accepted
time: 206ms
memory: 14508kb
input:
36000 30000 0 3 4 1 2 1 1 0 0 1 1 0 1 0 2 1 0 0 0 0 2 1 0 2 0 0 0 0 0 1 1 4 1 4 0 0 2 0 0 0 1 1 0 0 1 1 0 1 0 0 0 0 1 1 0 3 1 1 1 0 0 0 0 0 0 1 2 0 2 3 0 0 0 0 3 1 0 0 0 1 0 1 2 0 0 2 0 1 0 0 2 1 1 0 3 1 6 0 0 1 1 2 0 1 2 0 0 1 0 1 1 0 0 1 0 0 0 1 0 2 0 1 1 1 0 0 5 2 0 5 1 0 0 0 0 1 1 1 8 0 1 1 0 1 ...
output:
658813003
result:
ok 1 number(s): "658813003"
Test #9:
score: 0
Accepted
time: 2013ms
memory: 18776kb
input:
200000 200000 0 1 1 1 1 1 0 1 0 3 1 0 0 1 1 0 1 1 1 2 3 0 1 0 1 0 2 5 0 1 1 4 1 1 0 0 0 0 0 0 2 1 0 0 2 1 1 2 0 3 0 1 3 0 1 1 1 0 1 0 1 2 0 1 1 0 0 2 2 1 0 1 1 2 4 1 0 2 0 5 1 2 0 0 1 0 2 3 1 0 1 1 1 1 0 0 0 5 1 0 0 1 2 1 1 0 0 0 1 0 0 1 2 1 0 0 2 1 2 3 0 0 3 1 0 1 0 0 1 1 1 0 1 0 1 0 0 1 0 0 1 1 1 ...
output:
23477878007
result:
ok 1 number(s): "23477878007"
Test #10:
score: 0
Accepted
time: 2025ms
memory: 18392kb
input:
140000 200000 0 1 3 0 0 0 0 0 1 1 1 1 4 1 1 8 1 1 0 3 0 0 0 1 5 0 1 1 0 4 1 0 2 1 0 0 1 1 1 0 2 4 0 2 0 3 0 2 1 2 1 2 1 1 1 2 1 0 0 1 1 1 1 0 1 0 9 1 5 1 1 4 0 1 1 4 1 1 1 1 3 1 1 1 1 4 1 1 0 3 1 0 1 3 1 1 3 1 1 3 4 1 1 0 0 1 1 0 1 4 1 1 1 1 0 1 1 0 0 2 0 6 5 1 1 3 2 4 0 1 4 1 1 1 1 2 0 0 2 1 5 1 1 ...
output:
15405328745
result:
ok 1 number(s): "15405328745"
Test #11:
score: 0
Accepted
time: 2452ms
memory: 17944kb
input:
90000 200000 3 1 1 1 4 5 1 1 1 1 10 1 3 2 1 1 7 8 1 1 8 5 1 1 6 1 1 1 0 1 4 5 0 5 1 21 1 4 0 2 4 3 1 6 7 3 1 1 1 0 1 2 5 1 1 1 1 2 0 8 0 1 2 4 0 0 11 1 2 2 2 1 28 0 1 1 2 1 2 1 11 1 5 9 1 1 1 1 1 2 1 1 1 1 2 1 0 4 1 1 2 1 1 1 4 1 5 1 1 5 4 1 5 1 0 1 1 1 1 0 1 2 4 1 1 1 1 1 1 1 1 1 2 1 1 3 1 2 1 1 0 ...
output:
9895248405
result:
ok 1 number(s): "9895248405"
Test #12:
score: 0
Accepted
time: 2733ms
memory: 17572kb
input:
80000 200000 1 5 1 1 1 3 1 0 3 11 1 5 1 2 1 21 4 13 1 1 1 1 0 1 1 1 2 1 13 2 1 4 5 0 1 1 6 3 1 1 1 1 1 1 8 1 1 6 3 1 1 1 1 8 1 2 0 1 1 1 1 1 1 1 17 1 1 1 6 1 1 1 11 1 15 5 1 1 1 1 1 2 8 0 0 1 1 2 3 14 1 1 3 18 1 1 1 3 1 1 1 1 1 1 4 0 9 1 0 1 1 1 0 4 1 2 1 1 3 2 3 21 3 2 11 1 1 0 1 29 1 1 2 1 5 6 1 5...
output:
8980751457
result:
ok 1 number(s): "8980751457"
Test #13:
score: 0
Accepted
time: 3186ms
memory: 18460kb
input:
70000 200000 4 0 0 2 5 1 0 1 4 1 1 1 1 3 12 1 1 1 0 1 1 6 5 1 1 1 1 1 0 1 1 1 16 1 1 1 1 1 10 1 2 1 1 0 1 7 1 0 3 3 1 1 1 1 2 2 1 1 7 1 1 2 1 1 1 1 14 1 6 1 1 12 1 1 1 1 1 1 1 7 1 1 1 7 1 1 1 1 2 1 0 1 13 1 0 1 1 1 3 1 3 1 0 1 4 1 1 1 1 3 1 13 0 1 1 7 0 0 1 1 12 3 1 1 3 1 1 1 6 1 1 1 1 1 1 1 1 10 1 ...
output:
8196878191
result:
ok 1 number(s): "8196878191"
Test #14:
score: 0
Accepted
time: 3713ms
memory: 18560kb
input:
60000 200000 1 1 1 1 25 1 4 1 1 1 1 1 10 2 12 1 1 1 1 1 12 7 3 1 3 1 1 1 1 1 1 1 1 1 1 1 1 2 1 12 1 1 1 1 0 1 1 3 1 6 1 6 1 1 2 29 1 0 1 13 3 1 1 0 1 1 5 3 1 1 1 1 1 1 7 1 0 9 1 7 1 1 12 4 1 1 1 23 1 4 24 1 36 1 23 1 18 29 1 1 11 1 1 1 1 1 1 0 1 1 2 13 1 32 1 3 1 0 1 1 1 1 5 23 9 1 1 1 8 12 14 1 1 1...
output:
7466221263
result:
ok 1 number(s): "7466221263"
Test #15:
score: 0
Accepted
time: 4807ms
memory: 18280kb
input:
50000 200000 1 1 87 20 1 1 1 1 1 1 1 1 41 1 1 10 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 5 1 1 1 1 1 1 1 17 1 1 1 1 1 14 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 1 1 1 1 17 18 1 1 1 1 1 13 1 1 1 1 1 32 1 1 7 1 10 1 1 1 1 14 20 1 1 1 1 1 3 23 27 1 1 1 9 1 1 1 1 4 8 1 12 1 1 1 53 1 1 1 1 26 1 1 1 1 1 1 1 1 1 1 1...
output:
6870036861
result:
ok 1 number(s): "6870036861"
Test #16:
score: -100
Time Limit Exceeded
input:
45000 200000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 11 1 1 1 1 1 1 1 1 1 1 1 26 1 1 10 1 1 1 1 1 1 1 1 1 1 1 50 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 26 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 25 1 1 1 1...