QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#235090#7636. Fair Electionsucup-team1004WA 1ms4132kbC++142.9kb2023-11-02 13:43:332023-11-02 13:43:33

Judging History

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

  • [2023-11-02 13:43:33]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:4132kb
  • [2023-11-02 13:43:33]
  • 提交

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){}
	void reduce(){
		int n=-1,len=a.size();
		for(int i=0;i<len;i++){
			if(!~n||a[i].l>a[n].r+1)a[++n]=a[i];
			else a[n].r=max(a[n].r,a[i].r);
		}
		a.resize(n+1);
	}
	void merge(const Set &x){
		int mid=a.size();
		for(auto s:x.a)a.push_back(s);
		sort(a.begin(),a.end(),[&](seg x,seg y){return x.l<y.l;});
		// inplace_merge(a.begin(),a.begin()+mid,a.end(),[&](seg x,seg y){return x.l<y.l;});
		reduce();
	}
	void erase(const Set &x){
		int s1=a.size(),s2=x.a.size(),i=0,j=0;
		static vector<seg> res;
		res.clear();
		for(;i<s1&&j<s2;){
			int l=a[i].l,r=min(a[i].r,x.a[j].l-1);
			if(l<=r)res.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.push_back(a[i]);
		a.swap(res);
	}
};
Set f[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]--; 
		}
	}
	for(a[0]=0;a[0]<=n;a[0]++){
		vector<int>p;
		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;
			p.push_back(ans);
		}
		for(int len=p.size(),l=0,r;l<len;l=r){
			for(r=l;r<len&&p[l]==p[r];r++);
			f[a[0]][p[l]].a.push_back({l,r-1});
		}
		// for(int k=0;k<3;k++){
		// 	debug(n+1,a[0],k,f[now][a[0]][k].a);
		// }
	}
	for(int i=n;i>=1;i--){
		for(int j=0;j<i;j++){
			for(int k=0;k<3;k++){
				int t=p[i][k];
				for(auto &s:f[j][t].a)s.l--;
				f[j][t].merge(f[j+1][t]);
			}
			for(int x=0;x<3;x++){
				for(int y=0;y<x;y++){
					f[j][p[i][x]].erase(f[j][p[i][y]]);
				}
				// debug(i,j,t,f[now][j][p[i][x]].a);
			}
		}
		// if(i%200==0)debug(i,1.0*clock()/CLOCKS_PER_SEC/(n-i+1));
	}
	for(int k=0;k<3;k++){
		if(!f[0][k].a.empty()){
			cout<<k+1<<endl;break;
		}
	}
	debug(1.0*clock()/CLOCKS_PER_SEC);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 4080kb

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: 4132kb

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: 4092kb

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: 4068kb

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: -100
Wrong Answer
time: 1ms
memory: 4072kb

input:

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

output:

2

result:

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