結果

問題 No.3323 岩井星式ジャンケン
コンテスト
ユーザー tau1235
提出日時 2025-11-01 15:32:14
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 18 ms / 2,000 ms
コード長 1,143 bytes
コンパイル時間 3,161 ms
コンパイル使用メモリ 293,248 KB
実行使用メモリ 7,904 KB
最終ジャッジ日時 2025-11-01 15:32:20
合計ジャッジ時間 4,996 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 26
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In lambda function:
main.cpp:43:3: warning: control reaches end of non-void function [-Wreturn-type]
   43 |   };
      |   ^

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

int main(){
  map<char,int> mp;
  mp['G']=0;
  mp['C']=1;
  mp['P']=2;
  int n,m;
  cin>>n>>m;
  vector<string> s(n);
  for (int i=0;i<n;i++) cin>>s[i];
  string ans(m,'#');
  auto dfs=[&](auto dfs,vector<int> idx,int now)-> bool {
    vector<vector<int>> next(3);
    for (int i:idx) next[mp[s[i][now]]].push_back(i);
    vector<int> v;
    for (int i=0;i<3;i++) if (next[i].size()>0) v.push_back(i);
    int c=v.size();
    if (c==0){
      return true;
    }
    if (now==m) return false;
    if (c==1){
      ans[now]="GCP"[(v[0]+2)%3];
      return true;
    }
    if (c==2){
      int u1=(v[1]+2)%3,u0=(v[0]+2)%3;
      if ((v[0]+1)%3!=u1&&dfs(dfs,next[v[0]],now+1)){
        ans[now]="GCP"[u1];
        return true;
      }
      if ((v[1]+1)%3!=u0&&dfs(dfs,next[v[1]],now+1)){
        ans[now]="GCP"[u0];
        return true;
      }
      return false;
    }
    if (c==3){
      return false;
    }
  };
  vector<int> all(n);
  iota(all.begin(),all.end(),0);
  if (dfs(dfs,all,0)){
    for (int i=0;i<m;i++) if (ans[i]=='#') ans[i]='G';
    cout<<ans<<endl;
  }
  else cout<<-1<<endl;
}
0