QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#235016 | #7636. Fair Elections | ucup-team1004 | WA | 1118ms | 17400kb | C++14 | 4.4kb | 2023-11-02 10:51:29 | 2023-11-02 10:51:29 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#ifdef DEBUG
template<typename T>
ostream& operator << (ostream &out,const vector<T> &x){
if(x.empty())return out<<"[]";
out<<'['<<x[0];
for(int i=1,len=x.size();i<len;i++)out<<','<<x[i];
return out<<']';
}
template<typename T>
ostream& operator << (ostream &out,const deque<T> &x){
if(x.empty())return out<<"[]";
out<<'['<<x[0];
for(int i=1,len=x.size();i<len;i++)out<<','<<x[i];
return out<<']';
}
template<typename T>
vector<T> ary(const T *a,int l,int r){
return vector<T>{a+l,a+1+r};
}
template<typename T>
void debug(T x){
cerr<<x<<endl;
}
template<typename T,typename ... S>
void debug(T x,S...y){
cerr<<x<<' ',debug(y...);
}
#else
#define debug(...) void()
#endif
const int N=1e4+10;
int n,a[3],p[N][3];
int F(int a0,int a1){
int a2=n-a0-a1;
if(a0>=a1&&a0>=a2)return 0;
else if(a1>=a2)return 1;
else return 2;
}
using vec=complex<int>;
#ifdef DEBUG
ostream& operator << (ostream &out,const vec &x){
return out<<'('<<real(x)<<','<<imag(x)<<')';
}
#endif
void dfs(int L,int R,int lim,deque<vec>&p,vec s){
if(p.size()>lim)return;
int x=real(s),y=imag(s);
if(L==F(x-1,y-1)&&R==F(x-1,y)){
p.push_back(vec(x-1,y));
dfs(L,R,lim,p,vec(x-1,y));
}
if(L==F(x-1,y)&&R==F(x,y)){
p.push_back(vec(x,y+1));
dfs(L,R,lim,p,vec(x,y+1));
}
if(L==F(x,y)&&R==F(x,y-1)){
p.push_back(vec(x+1,y));
dfs(L,R,lim,p,vec(x+1,y));
}
if(L==F(x,y-1)&&R==F(x-1,y-1)){
p.push_back(vec(x,y-1));
dfs(L,R,lim,p,vec(x,y-1));
}
}
int main(){
cin>>n;
for(int i=1;i<=n;i++){
for(int j=0;j<3;j++){
cin>>p[i][j],p[i][j]--;
}
}
if(n==1){
cout<<p[1][0]+1<<endl,exit(0);
}
vec s;
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
fill(a,a+3,0);
for(int x:{i-1,i})for(int y:{j-1,j}){
a[F(x,y)]=1;
}
if(a[0]&&a[1]&&a[2]){
s=vec(i,j);break;
}
}
}
deque<vec>p02,p21,p10;
dfs(0,2,n*10+2,p02,s),dfs(2,1,n*10+2,p21,s),dfs(1,0,n*10+2,p10,s);
auto add=[&](deque<vec>&p,int x,int y){
for(auto &pt:p)pt+=vec(x,y);
};
auto reduce=[&](){
for(;p02.front()==p21.front();){
p10.push_front(s);
s=p02.front();
p02.pop_front(),p21.pop_front();
}
for(;p02.front()==p10.front();){
p21.push_front(s);
s=p02.front();
p02.pop_front(),p10.pop_front();
}
for(;p10.front()==p21.front();){
p02.push_front(s);
s=p10.front();
p10.pop_front(),p21.pop_front();
}
};
auto Up=[&](deque<vec> &p){
if(p.front()+vec(-1,0)==s){
p.pop_front(),add(p,-1,0);
}else{
add(p,-1,0);
p.push_front(s+vec(-1,0));
}
// debug("Up",p);
reduce();
};
auto Right=[&](deque<vec> &p){
if(p.front()+vec(0,-1)==s){
p.pop_front(),add(p,0,-1);
}else{
add(p,0,-1);
p.push_front(s+vec(0,-1));
}
reduce();
};
// debug(s);
// debug(p02);
// debug(p21);
// debug(p10);
// debug("");
for(int i=n;i>=1;i--){
string num="";
for(int j=0;j<3;j++)num+=char(p[i][j]+48);
if(num=="012"){
Up(p02),Up(p10),Right(p21);
}else if(num=="021"){
Up(p02),Up(p10);
}else if(num=="102"){
Right(p21),Right(p10),Up(p02);
}else if(num=="120"){
Right(p21),Right(p10);
}else if(num=="201"){
Up(p10);
}else if(num=="210"){
Right(p10);
}else assert(0);
// debug(s);
// debug(num,s,p02);
// debug(p21);
// debug(p10);
// debug("");
}
p21.push_front(s);
p10.push_front(s);
p02.push_front(s);
const int INF=1e9;
pair<int,int> L(-INF,0),R(INF,0),D(INF,0),U(-INF,0);
auto ins=[&](vec x,vec y,int z){
if(real(x)==0&&real(y)==1&&imag(x)>=1){
R=min(R,{imag(x),z});
}else if(real(x)==1&&real(y)==0&&imag(x)<=0){
L=max(L,{imag(x),z});
}else if(imag(x)==0&&imag(y)==1&&real(x)<=0){
U=max(U,{real(x),z});
}else if(imag(x)==1&&imag(y)==0&&real(x)>=1){
D=min(D,{real(x),z});
}
};
// debug(s);
// debug(p02);
// debug(p21);
// debug(p10);
// debug("");
for(int len=p21.size(),i=0;i+1<len;i++)ins(p21[i],p21[i+1],2);
for(int len=p10.size(),i=0;i+1<len;i++)ins(p10[i],p10[i+1],1);
for(int len=p02.size(),i=0;i+1<len;i++)ins(p02[i],p02[i+1],3);
// debug(L.first,L.second);
// debug(R.first,R.second);
// debug(D.first,D.second);
// debug(U.first,U.second);
if(L.second){
cout<<L.second<<endl;
}else if(R.second){
cout<<R.second<<endl;
}else if(D.second){
cout<<D.second<<endl;
}else if(U.second){
cout<<U.second<<endl;
}else assert(0);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3880kb
input:
3 3 2 1 1 2 3 2 1 3
output:
2
result:
ok 1 number(s): "2"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3576kb
input:
5 1 2 3 2 3 1 1 3 2 3 1 2 2 1 3
output:
1
result:
ok 1 number(s): "1"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3532kb
input:
5 1 2 3 3 2 1 1 2 3 1 2 3 3 2 1
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3648kb
input:
5 3 2 1 3 1 2 2 3 1 1 2 3 2 1 3
output:
2
result:
ok 1 number(s): "2"
Test #5:
score: 0
Accepted
time: 0ms
memory: 3844kb
input:
5 3 2 1 3 2 1 1 3 2 1 3 2 3 2 1
output:
3
result:
ok 1 number(s): "3"
Test #6:
score: 0
Accepted
time: 0ms
memory: 3580kb
input:
5 3 2 1 3 1 2 1 2 3 1 3 2 1 3 2
output:
1
result:
ok 1 number(s): "1"
Test #7:
score: 0
Accepted
time: 0ms
memory: 3868kb
input:
20 1 2 3 2 3 1 1 3 2 3 1 2 2 1 3 1 2 3 3 2 1 1 2 3 1 2 3 3 2 1 3 2 1 3 1 2 2 3 1 1 2 3 2 1 3 3 2 1 3 2 1 1 3 2 1 3 2 3 2 1
output:
1
result:
ok 1 number(s): "1"
Test #8:
score: 0
Accepted
time: 0ms
memory: 3608kb
input:
20 3 2 1 3 1 2 1 2 3 1 3 2 1 3 2 1 2 3 3 1 2 1 3 2 3 2 1 1 3 2 2 1 3 3 1 2 2 3 1 2 1 3 2 3 1 3 1 2 3 1 2 2 1 3 3 1 2 1 2 3
output:
1
result:
ok 1 number(s): "1"
Test #9:
score: 0
Accepted
time: 0ms
memory: 3900kb
input:
20 1 2 3 2 3 1 2 1 3 2 1 3 1 3 2 3 1 2 2 3 1 1 3 2 3 1 2 1 2 3 1 2 3 3 2 1 3 1 2 1 2 3 3 2 1 1 2 3 2 3 1 3 1 2 3 2 1 3 2 1
output:
3
result:
ok 1 number(s): "3"
Test #10:
score: 0
Accepted
time: 0ms
memory: 3644kb
input:
20 3 1 2 3 2 1 1 2 3 1 3 2 1 3 2 2 3 1 1 3 2 2 3 1 1 2 3 3 2 1 1 2 3 3 2 1 1 2 3 1 2 3 3 2 1 2 3 1 2 3 1 1 2 3 2 1 3 2 1 3
output:
1
result:
ok 1 number(s): "1"
Test #11:
score: 0
Accepted
time: 0ms
memory: 3608kb
input:
20 2 1 3 2 1 3 3 1 2 3 2 1 2 1 3 1 2 3 2 3 1 3 1 2 3 1 2 2 3 1 3 2 1 1 3 2 2 1 3 2 1 3 1 2 3 2 3 1 2 3 1 3 2 1 2 1 3 1 3 2
output:
2
result:
ok 1 number(s): "2"
Test #12:
score: 0
Accepted
time: 1088ms
memory: 17200kb
input:
10000 1 2 3 2 3 1 1 3 2 3 1 2 2 1 3 1 2 3 3 2 1 1 2 3 1 2 3 3 2 1 3 2 1 3 1 2 2 3 1 1 2 3 2 1 3 3 2 1 3 2 1 1 3 2 1 3 2 3 2 1 3 2 1 3 1 2 1 2 3 1 3 2 1 3 2 1 2 3 3 1 2 1 3 2 3 2 1 1 3 2 2 1 3 3 1 2 2 3 1 2 1 3 2 3 1 3 1 2 3 1 2 2 1 3 3 1 2 1 2 3 1 2 3 2 3 1 2 1 3 2 1 3 1 3 2 3 1 2 2 3 1 1 3 2 3 1 2 ...
output:
3
result:
ok 1 number(s): "3"
Test #13:
score: 0
Accepted
time: 1118ms
memory: 17332kb
input:
10000 2 1 3 1 3 2 3 2 1 3 1 2 1 3 2 2 1 3 2 3 1 1 3 2 1 3 2 2 1 3 3 2 1 3 1 2 3 1 2 3 1 2 2 3 1 1 2 3 3 2 1 2 1 3 3 2 1 3 1 2 2 1 3 1 2 3 2 1 3 2 1 3 2 1 3 2 1 3 2 3 1 2 3 1 3 2 1 3 2 1 3 1 2 3 2 1 1 2 3 1 2 3 1 2 3 2 3 1 1 3 2 1 2 3 2 3 1 1 3 2 2 1 3 2 3 1 2 3 1 3 1 2 1 3 2 3 1 2 3 2 1 1 2 3 1 3 2 ...
output:
3
result:
ok 1 number(s): "3"
Test #14:
score: -100
Wrong Answer
time: 1090ms
memory: 17400kb
input:
10000 3 2 1 3 1 2 3 2 1 3 2 1 3 1 2 1 3 2 3 1 2 1 3 2 2 3 1 1 3 2 3 1 2 3 2 1 3 1 2 1 2 3 3 2 1 3 1 2 3 1 2 1 2 3 2 3 1 3 1 2 3 2 1 3 2 1 3 2 1 2 3 1 3 1 2 3 1 2 1 2 3 3 2 1 3 1 2 3 1 2 1 2 3 2 3 1 3 1 2 2 1 3 1 2 3 2 3 1 2 3 1 1 2 3 3 1 2 2 1 3 1 3 2 1 2 3 1 2 3 1 2 3 1 3 2 3 1 2 1 2 3 2 1 3 3 2 1 ...
output:
2
result:
wrong answer 1st numbers differ - expected: '1', found: '2'