QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#390673#2833. HamiltonNahidameowWA 1ms3592kbC++201.9kb2024-04-15 19:49:172024-04-15 19:49:17

Judging History

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

  • [2024-04-15 19:49:17]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3592kb
  • [2024-04-15 19:49:17]
  • 提交

answer

#include<bits/stdc++.h>
#define pd push_back
#define all(A) A.begin(),A.end()
#define lower_bound lb
#define ve std::vector
typedef long long ll;
typedef long long ll;
typedef __int128 Int;
typedef unsigned long long ul;
typedef long double LD;
bool FileIfstream(std::string name){
	std::ifstream f(name.c_str());
	return f.good();
}
namespace Math{
	ll QP(ll x,ll y,ll mod){ll ans=1;for(;y;y>>=1,x=x*x%mod)if(y&1)ans=ans*x%mod;return ans;}
	ll inv(ll x,ll mod){return QP(x,mod-2,mod);}
}
const int N=2e5+10;
const int mod=998244353;
int n;
void solve(){
	//don't forget to open long long
	ve<std::string>v(n+1);
	for(int i=1;i<=n;i++){
		std::cin>>v[i];
		v[i]=" "+v[i];
	}
	ve<int>ans;ans.pd(1);ans.pd(2);
	auto insert=[&](int x,int y)->void{ans.insert(ans.begin()+x,y);};
	auto col=[&](int x,int y)->char{return v[x][y];};
	auto had=[&](int x)->char{int L=ans.size();return col(x%L,(x+1)%L);};
	for(int i=3;i<=n;i++){
		int L=ans.size();
		int pos=-1;
		for(int j=0;j+2<L;j++)
			if(had(j)!=had((j+1)%L))
				assert(pos==-1),pos=j;
		if(pos==-1){
			ans.pd(i);L++;
			for(int j=0;j+1<i;j++)
				if(had(j)!=had((j+1)%L)){
					rotate(ans.begin(),ans.begin()+j,ans.end());
					break;
				}
		}else{
			if(v[ans[pos]][i]==v[ans[(pos+1)%L]][i])
				insert(pos+1,i);
			else if(v[ans[(pos+1)%L]][i]==v[ans[(pos+2)%L]][i])
				insert(pos+2,i);
			else if(v[ans[(pos+1)%L]][i]==had(pos))
				insert(pos+2,i);
			else insert(pos+1,i); 
		}
//		for(auto &p:ans)
//			std::cerr<<p<<' ';
//		std::cerr<<'\n';
	}
	for(int i=0;i<n;i++)
		std::cout<<ans[i]<<(i==n-1?'\n':' ');
}
int main(){
#ifndef ONLINE_JUDGE
	if(!FileIfstream("IO.in")){
		freopen("IO.in","w",stdout);
		return 0;
	}
	freopen("IO.in","r",stdin);
	freopen("IO.out","w",stdout);
#endif
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	std::cout.tie(0);
	int T=1;
	while(std::cin>>n)solve();

	return 0;
}




Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
001
000
100
4
0000
0000
0000
0000

output:

1 2 3
1 4 2 3

result:

ok 2 cases.

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 3580kb

input:

3
000
000
000
3
010
100
000
3
011
100
100
3
011
101
110

output:

1 2 3
1 2 3
1 2 3
1 2 3

result:

wrong answer case #3: found 2 indices