結果

問題 No.3323 岩井星式ジャンケン
コンテスト
ユーザー のらら
提出日時 2025-10-30 19:37:11
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 54 ms / 2,000 ms
コード長 1,166 bytes
コンパイル時間 3,354 ms
コンパイル使用メモリ 185,824 KB
実行使用メモリ 30,292 KB
最終ジャッジ日時 2025-10-30 19:37:17
合計ジャッジ時間 4,797 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

//DFS(TLEかな)
#include <iostream>
#include <algorithm>
#include <atcoder/all>
#include <set>
using namespace std;
using namespace atcoder;
using ll = long long;
//#define endl "\n";
ll N, M, chk[100009];
string S[100009];
vector<char> ans;
vector<char> te = {'G', 'C', 'P'};
set<ll> rest;

void dfs(ll pos){
  if(pos == M){
    if(rest.size() == 0){
      for(auto s: ans) cout << s;
      cout << endl;
      exit(0);
    }else{
      return;
    }
  }
  vector<ll> visited(3, true);
  for(int k = 0; k < 3; k++){
    for(auto itr = rest.begin(); itr != rest.end(); ++itr){
      if(S[*itr][pos] == te[(k + 2) % 3]){
        visited[k] = false;
      }
    }
    if(visited[k]){
      vector<ll> tmp;
      for(auto itr = rest.begin(); itr != rest.end(); ++itr){
        if(S[*itr][pos] == te[(k + 1) % 3]){
          tmp.push_back(*itr);
        }
      }
      ans.push_back(te[k]);
      for(auto p: tmp) rest.erase(p);
      dfs(pos + 1);
      for(auto p: tmp) rest.insert(p);
      ans.pop_back();
    }
  }
}

int main(){
  cin >> N >> M;
  for(int i = 0; i < N; i++){
    cin >> S[i];
    rest.insert(i);
  }
  dfs(0);
  cout << -1 << endl;
  return 0;
}
0