QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#333719#6537. One, Two, ThreeECqwqWA 1ms3864kbC++141.6kb2024-02-20 13:47:472024-02-20 13:47:47

Judging History

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

  • [2024-02-20 13:47:47]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3864kb
  • [2024-02-20 13:47:47]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int maxn=1e4+5;
int n,a[maxn],ans,ansx,ansy;
int pos[4][maxn],num[4],vis[maxn];
vector<pair<int, int> > vec[maxn];
bool check(int x,int y)
{
	if(x+y>min(num[1],min(num[2],num[3]))) return 0;
	for(int i=1;i<=x;i++)
		vec[pos[3][num[3]-(x-i)]].push_back(make_pair(pos[1][i],0));
	for(int i=1;i<=y;i++)
		vec[pos[1][num[1]-(y-i)]].push_back(make_pair(pos[3][i],1));
	int p[2]={0,0},l,r,k,ret=1;
	for(int i=1;i<=n;i++)
	{
		r=i;
		for(int j=0;j<vec[i].size();j++)
		{
			l=vec[i][j].first,k=vec[i][j].second;
			if(l>r) ret=0;
			p[k]=max(p[k],l);
			while(p[k]<r && (vis[p[k]]==1 || a[p[k]]!=2)) p[k]++;
			if(vis[p[k]]==0 && a[p[k]]==2) vis[p[k]]=1;
			else ret=0;
			if(ret==0) break;
		}
		if(ret==0) break;
	}
	for(int i=1;i<=n;i++) vis[i]=0,vec[i].clear();
	return ret;
}
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		pos[a[i]][++num[a[i]]]=i;
	}
	int y=0;
	for(int x=0;x<=n/3;x++)
	{
		while(check(x,y+1)) y++;
		if(check(x,y) && x+y>ans) ans=x+y,ansx=x,ansy=y;
	}
	cout<<ans<<'\n';
	for(int i=1;i<=ansx;i++)
		vec[pos[3][num[3]-(ansx-i)]].push_back(make_pair(pos[1][i],0));
	for(int i=1;i<=ansy;i++)
		vec[pos[1][num[1]-(ansy-i)]].push_back(make_pair(pos[3][i],1));
	int p[2]={0,0},l,r,k;
	for(int i=1;i<=n;i++)
	{
		r=i;
		for(int j=0;j<vec[i].size();j++)
		{
			l=vec[i][j].first,k=vec[i][j].second;
			p[k]=max(p[k],l);
			while(p[k]<r && (vis[p[k]]==1 || a[p[k]]!=2)) p[k]++;
			vis[p[k]]=1;
			cout<<l<<' '<<p[k]<<' '<<r<<'\n';
		}
	}
	return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3864kb

input:

6
3 1 2 2 3 1

output:

2
2 3 5
1 4 6

result:

wrong answer no 1 2 3 or 3 2 1