이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define sf scanf
#define pf printf
#define fi first
#define se second
#define pb push_back
#define INF 2023456789
#define sz(x) ((int)x.size())
#define all(x) x.begin(),x.end()
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ll,ll> pll;
const int m=4000;
int n,k;
int num[2*m+5];
int grid[m+5][m+5];
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
int main(){
sf("%d%d",&n,&k);
vector<ii> v;
bool st1=true,st2=true;
for(int i=0;i<n;++i){
int x,y;sf("%d%d",&x,&y);
v.pb({x,y});
st1=st1&&(max(abs(x),abs(y))<=1000);
st2=st2&&(x==y);
}
if(st1){
memset(grid,-1,sizeof grid);
queue<ii> q;
for(auto[x,y]:v){
x+=m/2;y+=m/2;
grid[x][y]=0;
q.push({x,y});
}
while(!q.empty()){
auto[x,y]=q.front();q.pop();
for(int i=0;i<4;++i){
int nx=x+dx[i],ny=y+dy[i];
if(nx<0||ny<0||nx>=m||ny>=m)continue;
if(grid[nx][ny]!=-1)continue;
grid[nx][ny]=grid[x][y]+1;
q.push({nx,ny});
}
}
for(int i=0;i<m;++i){
for(int j=0;j<m;++j){
++num[grid[i][j]];
}
}
for(int i=0;i<k;++i){
int x;sf("%d",&x);
pf("%d\n",num[x]);
}
}
else if(st2){
set<pll> s;
ll tot=0;
priority_queue<pll,vector<pll>,greater<pll>> pq;
sort(all(v));
for(int i=0;i<sz(v);++i){
v[i]={v[i].fi+v[i].se,0};
ll x=v[i].fi;
if(i!=0){
ll pv=v[i-1].fi;
pq.push({x-pv,pv});
}
s.insert({x,x});
}
for(int i=0;i<k;++i){
int x;sf("%d",&x);
if(x==0){
pf("%d\n",n);
continue;
}
int bonus=0;
while(!pq.empty()&&pq.top().fi<=2*x){
auto[d,v]=pq.top();
pq.pop();
if(d==2*x)++bonus;
auto it=--(s.upper_bound({v,INF}));
while(next(it)==s.begin())pf("hi\n");
pll pr=*it;
while(!(pr.fi<=v&&v<=pr.se))pf("hi\n");
it=s.erase(it);
while(it==s.end())pf("hi\n");
pll pr2=*it;
s.erase(it);
tot-=pr.se-pr.fi;
tot-=pr2.se-pr2.fi;
tot+=pr2.se-pr.fi;
s.insert({pr.fi,pr2.se});
}
int num=sz(s);
pf("%lld\n",(ll)num*4*x+tot+(ll)bonus*(x-1));
}
}
}
컴파일 시 표준 에러 (stderr) 메시지
cell.cpp: In function 'int main()':
cell.cpp:24:4: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
24 | sf("%d%d",&n,&k);
| ^
cell.cpp:28:13: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
28 | int x,y;sf("%d%d",&x,&y);
| ^
cell.cpp:57:12: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
57 | int x;sf("%d",&x);
| ^
cell.cpp:76:12: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
76 | int x;sf("%d",&x);
| ^
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |