QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#370696 | #6354. 4 | 369Pai | WA | 7ms | 50444kb | C++14 | 1.4kb | 2024-03-29 15:20:46 | 2024-03-29 15:22:18 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int , int> pr;
const int N = 2e5 + 5 , S = N * 5;
int n , s , tot , c[S]; pr a[N];
vector<pr>f[S] , g[S];
int main()
{
ios::sync_with_stdio(0);
cin.tie(0) , cout.tie(0);
cin >> n >> s;
for(int i = 1 , x ; i <= n ; i++)
cin >> x , c[x]++;
for(int i = 0 ; i <= s ; i++)
{
int x = i == 1 ? 0 : c[i];
for(int j = 1 ; j <= x ; j <<= 1)
a[++tot] = {j , i * j} , x -= j;
if(x)a[++tot] = {x , i * x};
}
f[c[0]] = {pr(0 , c[1])};
for(int i = 1 ; i <= tot ; i++)
{
auto [x , y] = a[i];
// cerr << x << ',' << y << "\n";
for(int j = 0 ; j <= s + c[0] ; j++)g[j] = f[j];
for(int j = 0 ; j <= s + c[0] ; j++)
for(auto [l , r] : f[j])g[j + y - x].push_back(pr(l + y , r + y));
for(int j = 0 ; j <= s + c[0] ; j++)
{
int L = 0 , R = -1; f[j].clear();
sort(g[j].begin() , g[j].end());
for(auto [l , r] : g[j])
{
if(R + 1 < l)
{
if(R >= L)f[j].push_back({L , R});
L = l;
}
R = max(R , r);
}
if(R >= L)f[j].push_back({L , R});
// if(!f[j].empty())
// {
// cerr << j - c[0] << ":";
// for(auto [l , r] : f[j])cerr << "(" << l << ',' << r << ")";
// cerr << "\n";
// }
}
}
ll ans = 0;
for(int i = 0 ; i <= s + c[0] ; i++)
for(auto [l , r] : f[i])ans += r - l + 1;
cout << ans << "\n";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 7ms
memory: 50444kb
input:
5 9 1 2 1 3 1 4 1 5 2 3 2 4 2 5 3 4 3 5
output:
16
result:
wrong answer 1st numbers differ - expected: '2', found: '16'