結果

問題 No.1370 置換門松列
ユーザー 👑 kmjpkmjp
提出日時 2021-01-29 22:40:55
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 31 ms / 2,000 ms
コード長 1,493 bytes
コンパイル時間 2,166 ms
コンパイル使用メモリ 205,068 KB
実行使用メモリ 8,944 KB
最終ジャッジ日時 2023-10-12 21:03:19
合計ジャッジ時間 4,037 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,740 KB
testcase_01 AC 3 ms
5,744 KB
testcase_02 AC 4 ms
5,836 KB
testcase_03 AC 3 ms
5,776 KB
testcase_04 AC 3 ms
5,836 KB
testcase_05 AC 3 ms
5,736 KB
testcase_06 AC 3 ms
5,720 KB
testcase_07 AC 4 ms
5,920 KB
testcase_08 AC 3 ms
5,776 KB
testcase_09 AC 4 ms
5,824 KB
testcase_10 AC 4 ms
5,828 KB
testcase_11 AC 3 ms
5,836 KB
testcase_12 AC 3 ms
5,716 KB
testcase_13 AC 3 ms
5,808 KB
testcase_14 AC 4 ms
5,776 KB
testcase_15 AC 3 ms
5,812 KB
testcase_16 AC 3 ms
5,832 KB
testcase_17 AC 4 ms
5,732 KB
testcase_18 AC 3 ms
5,828 KB
testcase_19 AC 3 ms
5,736 KB
testcase_20 AC 4 ms
5,896 KB
testcase_21 AC 25 ms
8,884 KB
testcase_22 AC 17 ms
7,540 KB
testcase_23 AC 23 ms
7,592 KB
testcase_24 AC 10 ms
6,784 KB
testcase_25 AC 31 ms
8,776 KB
testcase_26 AC 31 ms
8,944 KB
testcase_27 AC 14 ms
7,632 KB
testcase_28 AC 13 ms
7,460 KB
testcase_29 AC 11 ms
6,916 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

int N,M;
int A[101010];

vector<int> E[101010];
int in[101010];
int ret[101010];
void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>M;
	FOR(i,N) cin>>A[i], A[i]--;
	
	FOR(i,N-1) if(A[i]==A[i+1]) return _P("No\n");
	FOR(i,N-2) if(A[i]==A[i+2]) return _P("No\n");
	FOR(i,N-1) {
		if(i%2==0) {
			E[A[i]].push_back(A[i+1]);
			in[A[i+1]]++;
		}
		else {
			E[A[i+1]].push_back(A[i]);
			in[A[i]]++;
		}
	}
	
	queue<int> Q;
	FOR(i,M) if(in[i]==0) Q.push(i);
	int cur=0;
	while(Q.size()) {
		x=Q.front();
		Q.pop();
		ret[x]=++cur;
		FORR(e,E[x]) {
			in[e]--;
			if(in[e]==0) Q.push(e);
		}
	}
	if(cur!=M) return _P("No\n");
	cout<<"Yes"<<endl;
	FOR(i,M) cout<<ret[i]<<" ";
	cout<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0