結果

問題 No.1370 置換門松列
ユーザー snow39snow39
提出日時 2021-01-29 22:50:01
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 32 ms / 2,000 ms
コード長 1,552 bytes
コンパイル時間 933 ms
コンパイル使用メモリ 99,864 KB
実行使用メモリ 8,324 KB
最終ジャッジ日時 2023-10-12 21:03:30
合計ジャッジ時間 2,780 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 2 ms
4,352 KB
testcase_04 AC 1 ms
4,352 KB
testcase_05 AC 1 ms
4,352 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 2 ms
4,352 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,352 KB
testcase_10 AC 2 ms
4,352 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 1 ms
4,352 KB
testcase_13 AC 1 ms
4,352 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 1 ms
4,352 KB
testcase_16 AC 1 ms
4,348 KB
testcase_17 AC 1 ms
4,352 KB
testcase_18 AC 1 ms
4,352 KB
testcase_19 AC 2 ms
4,352 KB
testcase_20 AC 2 ms
4,352 KB
testcase_21 AC 26 ms
8,216 KB
testcase_22 AC 23 ms
7,876 KB
testcase_23 AC 24 ms
7,816 KB
testcase_24 AC 9 ms
4,372 KB
testcase_25 AC 32 ms
8,324 KB
testcase_26 AC 30 ms
8,288 KB
testcase_27 AC 17 ms
7,876 KB
testcase_28 AC 17 ms
7,740 KB
testcase_29 AC 11 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  int N,M;
  cin>>N>>M;
  vector<int> A(N);
  rep(i,N) cin>>A[i];

  rep(i,N) A[i]--;

  for(int i=0;i+1<N;i++){
    if(A[i]==A[i+1]){
      cout<<"No"<<endl;
      return 0;
    }
  }
  for(int i=0;i+2<N;i++){
    if(A[i]==A[i+2]){
      cout<<"No"<<endl;
      return 0;
    }
  }

  for(int t=0;t<2;t++){
    vector<vector<int>> g(M);
    for(int i=0;i+1<N;i++){
      if(i%2==t){// >
        g[A[i+1]].push_back(A[i]);
      }else{
        g[A[i]].push_back(A[i+1]);
      }
    }

    vector<int> in(M,0);
    rep(i,M) for(auto to:g[i]) in[to]++;
    vector<int> ans(M,-1);
    int cnt=0;
    queue<int> Q;
    rep(i,M) if(in[i]==0){
      Q.push(i);
    }
    
    while(!Q.empty()){
      int now=Q.front();
      Q.pop();

      ans[now]=cnt++;

      for(auto nex:g[now]){
        in[nex]--;
        if(in[nex]==0) Q.push(nex);
      }
    }

    if(cnt==M){
      cout<<"Yes"<<endl;
      rep(i,M) cout<<ans[i]+1<<" ";
      cout<<endl;
      return 0;
    }
  }

  cout<<"No"<<endl;

  return 0;
}
0