QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#235074 | #7636. Fair Elections | ucup-team1004 | TL | 1ms | 4900kb | C++14 | 3.5kb | 2023-11-02 13:03:19 | 2023-11-02 13:03:19 |
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];
struct seg{
int l,r;
seg(int x=1,int y=0):l(x),r(y){}
};
struct Set{
vector<seg>a;
Set(vector<seg>x=vector<seg>()):a(x){}
Set operator -= (const int &x){
for(seg &t:a)t.l-=x,t.r-=x;
return *this;
}
Set operator - (const int &x)const{
return Set(*this)-=x;
}
Set operator & (const Set &x)const{
int s1=a.size(),s2=x.a.size(),i=0,j=0;
Set res;
for(;i<s1&&j<s2;){
int l=max(a[i].l,x.a[j].l),r=min(a[i].r,x.a[j].r);
if(l<=r)res.a.push_back({l,r});
if(a[i].l<x.a[j].l)i++;
else j++;
}
// debug(a,x.a,res.a);
return res;
}
Set operator &= (const Set &x){
return *this=*this&x;
}
Set operator | (const Set &x)const{
Set res;
res.a.resize(a.size()+x.a.size());
merge(a.begin(),a.end(),x.a.begin(),x.a.end(),res.a.begin(),[&](seg x,seg y){return x.l<y.l;});
Set ans;
int len=-1;
for(seg x:res.a){
if(!~len||x.l>ans.a.back().r+1)ans.a.push_back(x),len++;
else ans.a[len].r=max(ans.a[len].r,x.r);
}
return ans;
}
Set operator |= (const Set &x){
return *this=*this|x;
}
Set operator -= (const Set &x){
int s1=a.size(),s2=x.a.size(),i=0,j=0;
Set res;
for(;i<s1&&j<s2;){
int l=a[i].l,r=min(a[i].r,x.a[j].l-1);
if(l<=r)res.a.push_back({l,r});
a[i].l=max(a[i].l,x.a[j].r+1);
if(a[i].r<x.a[j].r)i++;
else j++;
}
for(;i<s1;i++)if(a[i].l<=a[i].r)res.a.push_back(a[i]);
// debug(a,x.a,res.a);
return *this=res;
}
Set operator - (const Set &x)const{
return Set(*this)-=x;
}
};
Set f[2][N][3];
#ifdef DEBUG
ostream& operator << (ostream &out,const seg &x){
return out<<'('<<x.l<<','<<x.r<<')';
}
#endif
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]--;
}
}
int now=0,las=1;
for(a[0]=0;a[0]<=n;a[0]++){
for(a[1]=0;a[0]+a[1]<=n;a[1]++){
a[2]=n-a[0]-a[1];
int ans=0;
for(int i=1;i<3;i++)if(a[ans]<a[i])ans=i;
f[now][a[0]][ans]|=Set({seg(a[1],a[1])});
}
// for(int k=0;k<3;k++){
// debug(n+1,a[0],k,f[now][a[0]][k].a);
// }
}
auto ins=[&](int n,int i,int j,Set x){
x&=Set({seg(0,n)});
// if(n==10-1-0&&i==0&&j==1)debug("\t",x.a);
for(int k=0;k<3;k++)if(k^j){
x-=f[now][i][k];
// if(n==10-1-0&&i==0&&j==1)debug("\t",x.a,f[now][i][k].a);
}
// if(n==10-1-0&&i==0&&j==1)debug("\t",x.a);
f[now][i][j]|=x;
};
for(int i=n;i>=1;i--){
swap(now,las);
for(int j=0;j<i;j++){
for(int k=0;k<3;k++){
f[now][j][k]=Set();
}
}
for(int j=0;j<i;j++){
for(int k=0;k<3;k++){
int t=p[i][k];
ins(i-1-j,j,t,f[las][j][t]|f[las][j+1][t]|(f[las][j][t]-1));
// debug(i,j,t,f[now][j][t].a);
}
}
}
for(int k=0;k<3;k++){
if(!f[now][0][k].a.empty()){
cout<<k+1<<endl,exit(0);
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 4816kb
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: 1ms
memory: 4800kb
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: 4900kb
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: 1ms
memory: 4808kb
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: 4784kb
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: 1ms
memory: 4900kb
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: 4820kb
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: 1ms
memory: 4848kb
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: 1ms
memory: 4852kb
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: 1ms
memory: 4848kb
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: 1ms
memory: 4844kb
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: -100
Time Limit Exceeded
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 ...