이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "teams.h"
#include<bits/stdc++.h>
#define ll long long
#define MAXN 500500
#define MAXM 2024
#define fs first
#define sn second
using namespace std;
int n,B,x,y,now,w,sum,v[MAXM],c[MAXM],h[MAXN][800],g[MAXM][MAXM],f[MAXM][MAXM];
vector<pair<int,int> >d[800];
pair<int,int>a[MAXN];
void init(int N, int A[], int BB[]) {
n=N;
B=800;
for(int i=0;i<=n;++i)
for(int j=0;j<=n/B;++j)
h[i][j]=0;
for(int i=1;i<=n;++i)
a[i]=make_pair(A[i-1],BB[i-1]);
sort(a+1,a+1+n);
for(int i=1;i<=n;++i){
tie(x,y)=tie(a[i].fs,a[i].sn);
h[y][i/B]++;
d[i/B].push_back({x,y});
}
for(int i=0;i<=n/B;++i)
sort(d[i].begin(),d[i].end(),[](pair<int,int>a,pair<int,int>b){return (a.sn>b.sn);});
for(int i=1;i<=n;++i)
for(int j=1;j<=n/B;++j)
h[i][j]+=h[i][j-1];
for(int i=n-1;i>0;--i)
for(int j=0;j<=n/B;++j)
h[i][j]+=h[i+1][j];
return;
}
int can(int M, int K[]) {
sum=0;
w=0;
sort(K,K+M);
for(int i=0;i<M;++i){
sum+=K[i];
if(sum>n)return 0;
if(!w||v[w]!=K[i])v[++w]=K[i],c[w]=K[i];
else c[w]+=K[i];
}
for(int i=0;i<=w+1;++i)
for(int j=0;j<=w+1;++j)
f[i][j]=g[i][j]=0;
for(int i=1;i<=w;++i){
now=0;
while((now+1)*B<=n&&a[(now+1)*B].fs<=v[i])now++;
sum=0;
x=0;
for(int j=w;j>=i;--j){
while(x<d[now].size()&&d[now][x].sn>=v[j]){
if(d[now][x].fs<=v[i])sum++;
x++;
}
g[i][j]=(now>0?h[v[j]][now-1]:0)+sum;
}
}
for(int i=1;i<=w;++i)
for(int j=i;j<=w;++j)
f[i][j]=g[i][j]-g[i-1][j]-g[i][j+1]+g[i-1][j+1];
for(int i=1;i<=w;++i){
for(int j=i;j<=w;++j){
x=min(c[i],f[i][j]);
f[i][j]-=x;
c[i]-=x;
}
if(c[i])return 0;
for(int j=i+1;j<=w;++j)
f[i+1][j]+=f[i][j];
}
return 1;
}
컴파일 시 표준 에러 (stderr) 메시지
teams.cpp: In lambda function:
teams.cpp:27:48: warning: declaration of 'a' shadows a global declaration [-Wshadow]
27 | sort(d[i].begin(),d[i].end(),[](pair<int,int>a,pair<int,int>b){return (a.sn>b.sn);});
| ~~~~~~~~~~~~~^
teams.cpp:11:14: note: shadowed declaration is here
11 | pair<int,int>a[MAXN];
| ^
teams.cpp: In function 'int can(int, int*)':
teams.cpp:56:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
56 | while(x<d[now].size()&&d[now][x].sn>=v[j]){
| ~^~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |