QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#235066#7636. Fair Electionsucup-team1004WA 1ms5052kbC++143.3kb2023-11-02 12:42:522023-11-02 12:42:52

Judging History

你现在查看的是最新测评结果

  • [2023-11-02 12:42:52]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5052kb
  • [2023-11-02 12:42:52]
  • 提交

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++;
		}
		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;)res.a.push_back(a[i++]);
		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)});
		for(int k=0;k<3;k++)if(k^j)x-=f[now][i][k];
		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++){
				int t=p[i][k];
				ins(i-1,j,t,f[las][j][t]|f[las][j+1][t]|(f[las][j][t]-1));
			}
			// for(int k=0;k<3;k++){
			// 	debug(i,j,k,f[now][j][k].a);
			// }
		}
	}
	for(int k=0;k<3;k++){
		if(!f[1][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: 1ms
memory: 5052kb

input:

3
3 2 1
1 2 3
2 1 3

output:

2

result:

ok 1 number(s): "2"

Test #2:

score: -100
Wrong Answer
time: 1ms
memory: 5052kb

input:

5
1 2 3
2 3 1
1 3 2
3 1 2
2 1 3

output:

2

result:

wrong answer 1st numbers differ - expected: '1', found: '2'