QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#740206 | #9170. Cycle Game | ucup-team134 | WA | 1ms | 4028kb | C++17 | 4.2kb | 2024-11-13 03:44:02 | 2024-11-13 03:44:02 |
Judging History
answer
#pragma GCC optimize("O3,unroll-loops")
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define f first
#define s second
#define sz(x) (int)(x).size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define ios ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ld long double
#define li __int128
using namespace std;
mt19937 rng(time(NULL));
const int N=3e5+5;
struct dsu{
vector<int> par,siz;
vector<pair<int,pair<int,int>>> old;
int cntComp,cntCompsnap;
bool activeSnap;
void reset(int n){
par.resize(n);
siz.resize(n);
iota(all(par),0);
fill(all(siz),1);
old.clear();
cntComp=n;
activeSnap=0;
}
void snapshot(){
old.clear();
cntCompsnap=cntComp;
activeSnap=1;
}
void goToSnapshot(){
for(auto p:old){
par[p.f]=p.s.f;
siz[p.f]=p.s.s;
}
old.clear();
cntComp=cntCompsnap;
}
inline int find(int tr){return tr==par[tr]?tr:find(par[tr]);}
inline void merge(int a,int b){
a=find(a);
b=find(b);
if(a==b)return;
cntComp--;
if(siz[a]>siz[b])swap(a,b);
if(activeSnap){
old.pb({a,{par[a],siz[a]}});
}
par[a]=b;
siz[b]+=siz[a];
}
}dsu;
vector<int> dx={1,1,1,0,-1,-1,-1,0},dy={1,0,-1,-1,-1,0,1,1};
int main()
{
ios;
int n,m,k;
cin>>n>>m>>k;
bool mx=0;
if(n==-1){
n=75000;
m=4;
k=3e5;
mx=1;
}
vector<pair<int,int>> ord;
int C=3000;
auto inside=[&](int x,int y){
return x>=0&&x<n&&y>=0&&y<m;
};
auto ind=[&](int x,int y){
return x*m+y;
};
auto onBorder=[&](int x,int y){
return x==0||y==0||x==n-1||y==m-1;
};
if(mx){
for(int i=0;i<n;i++)for(int j=0;j<m;j++)ord.pb({i,j});
shuffle(all(ord),rng);
}
else{
for(int i=0;i<k;i++){
int x,y;
if(mx){
x=1;
y=rng()%m+1;
}
else
cin >> x >> y;
x--;y--;
ord.pb({x,y});
}
}
vector<vector<bool>> on(n,vector<bool>(m));
vector<vector<int>> next(n,vector<int>(m));
int cnt8=0;
int cntOn=0;
auto add=[&](int i,int j){
for(int kk=0;kk<8;kk++){
int x=i+dx[kk],y=j+dy[kk];
if(inside(x,y)&&on[x][y]){
next[x][y]++;
if(next[x][y]==8)cnt8++;
}
}
cntOn++;
};
auto sub=[&](int i,int j){
for(int kk=0;kk<8;kk++){
int x=i+dx[kk],y=j+dy[kk];
if(inside(x,y)&&on[x][y]){
if(next[x][y]==8)cnt8--;
next[x][y]--;
}
}
cntOn--;
};
vector<bool> ok(k,1);
int cntDo=0;
ll resetTime=0;
for(int i=0;i<k;){
int ost=min(C,k-i);
int j=i+ost;
//printf("%i->%i\n",i,j);
for(int o=i;o<j;o++){
int x=ord[o].f,y=ord[o].s;
on[x][y]=1;
add(x,y);
}
C-=21;C=max(C,400);
ll st=clock();
dsu.reset(n*m+1);
for(int x=0;x<n;x++){
for(int y=0;y<m;y++){
if(!on[x][y]){
if(onBorder(x,y)){
dsu.merge(ind(x,y),n*m);
}
for(int kk=0;kk<4;kk++){
int xx=x+dx[kk],yy=y+dy[kk];
if(inside(xx,yy)&&!on[xx][yy]){
dsu.merge(ind(x,y),ind(xx,yy));
}
}
}
}
}
resetTime+=clock()-st;
cntDo++;
//printf("CntComp: %i\n",dsu.cntComp);
int cntBack=0;
while(1){
if(dsu.cntComp-cntOn==1&&cnt8==0){ // everything is ok
break;
}
cntBack++;
dsu.snapshot();
for(int o=j-1;o>=i-1;o--){
assert(o!=i-1);
int x=ord[o].f,y=ord[o].s;
assert(on[x][y]);
on[x][y]=0;
sub(x,y);
if(onBorder(x,y)){
dsu.merge(ind(x,y),n*m);
}
for(int kk=0;kk<8;kk++){
int xx=x+dx[kk],yy=y+dy[kk];
if(inside(xx,yy)&&!on[xx][yy]){
dsu.merge(ind(x,y),ind(xx,yy));
}
}
if(dsu.cntComp-cntOn==1&&cnt8==0){
ok[o]=0;
dsu.goToSnapshot();
for(int p=o+1;p<j;p++){
on[ord[p].f][ord[p].s]=1;
add(ord[p].f,ord[p].s);
}
if(onBorder(x,y)){
dsu.merge(ind(x,y),n*m);
}
for(int kk=0;kk<8;kk++){
int xx=x+dx[kk],yy=y+dy[kk];
if(inside(xx,yy)&&!on[xx][yy]){
dsu.merge(ind(x,y),ind(xx,yy));
}
}
break;
}
}
}
/*if(cntBack<10){
C*=1.3;
}
else{
C/=1.5;
C=max(C,600);
}*/
i=j;
}
if(mx)
printf("%i\n",cntDo),printf("%lld\n",resetTime),printf("C: %i\n",C);
for(int i=0;i<k;i++){
printf(ok[i]?"1":"0");
}
printf("\n");
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 4024kb
input:
4 3 7 2 1 2 2 2 3 3 1 3 2 4 1 4 2
output:
1111111
result:
ok "1111111"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3996kb
input:
3 3 8 1 1 1 2 1 3 2 3 3 3 3 2 3 1 2 1
output:
11111110
result:
ok "11111110"
Test #3:
score: 0
Accepted
time: 0ms
memory: 4028kb
input:
10 10 7 9 1 6 6 3 8 8 7 5 10 1 7 1 2
output:
1111111
result:
ok "1111111"
Test #4:
score: 0
Accepted
time: 0ms
memory: 4024kb
input:
9 10 50 1 9 1 6 2 3 3 1 7 4 9 4 1 3 2 5 9 2 7 9 5 6 8 10 9 5 5 5 4 10 9 7 5 9 3 2 4 5 1 1 4 7 3 6 2 8 4 3 8 6 5 10 4 8 5 4 7 2 9 6 4 2 7 8 5 2 3 5 9 1 6 1 1 5 9 9 5 8 6 3 8 8 8 4 7 7 7 1 3 7 2 2 3 10 6 9 8 3 7 6
output:
11111111111111111111111111111111111111111111111111
result:
ok "11111111111111111111111111111111111111111111111111"
Test #5:
score: 0
Accepted
time: 0ms
memory: 3828kb
input:
3 5 11 1 5 2 4 1 2 1 3 3 3 3 1 3 4 2 3 1 4 2 1 2 5
output:
11111111111
result:
ok "11111111111"
Test #6:
score: 0
Accepted
time: 0ms
memory: 3840kb
input:
7 9 12 7 3 2 3 6 2 2 2 4 2 2 8 5 7 4 4 6 8 2 7 7 2 1 9
output:
111111111111
result:
ok "111111111111"
Test #7:
score: 0
Accepted
time: 1ms
memory: 3844kb
input:
1 4 1 1 2
output:
1
result:
ok "1"
Test #8:
score: -100
Wrong Answer
time: 1ms
memory: 3996kb
input:
9 8 67 5 5 8 3 9 5 7 4 5 1 9 3 4 2 2 5 1 7 7 8 7 2 8 5 6 1 8 8 4 4 5 4 1 5 3 4 6 7 2 3 3 7 5 7 2 4 2 7 1 3 7 3 2 8 6 6 6 2 6 3 7 5 9 6 7 6 3 6 1 1 6 4 3 1 5 3 8 7 2 1 4 1 8 4 8 6 3 5 5 8 1 6 1 2 4 6 9 4 1 4 3 3 4 8 8 1 4 7 9 8 3 8 6 5 6 8 3 2 2 2 7 1 9 2 4 3 1 8 4 5 8 2 7 7
output:
1111111111111111111111111111111111111111111110011111101010001101101
result:
wrong answer 1st words differ - expected: '111111111111111111111111111111...1111111110010101101000101101101', found: '111111111111111111111111111111...1111111110011111101010001101101'