結果

問題 No.3323 岩井星式ジャンケン
コンテスト
ユーザー のらら
提出日時 2025-10-31 00:25:17
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,674 bytes
コンパイル時間 3,508 ms
コンパイル使用メモリ 185,500 KB
実行使用メモリ 11,548 KB
最終ジャッジ日時 2025-10-31 20:40:10
合計ジャッジ時間 5,361 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 3
other WA * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

//入力チェック+解が確定するjを求める
#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);
        }
      }
      if(tmp.size() == 0 && rest.size() > 0) continue; //あいこにする必要はない
      ans.push_back(te[k]);
      for(auto p: tmp) rest.erase(p);
      if(rest.size() == 0){
        cout << "OK idx=" << pos + 1 << endl;
        exit(0);
      }
      dfs(pos + 1);
      for(auto p: tmp) rest.insert(p);
      ans.pop_back();
    }
  }
  cout << "NG idx=" << pos + 1 << endl;
  exit(0);
}

int main(){
  cin >> N >> M;
  assert(1 <= N && N <= 1e5);
  assert(1 <= M && M <= 1e5);
  assert(1 <= N * M && N * M<= 1e5);
  for(int i = 0; i < N; i++){
    cin >> S[i];
    assert(S[i].size() == M);
    for(int j = 0; j < M; j++){
      assert(S[i][j] == 'G' || S[i][j] == 'C' || S[i][j] == 'P');
    }
    rest.insert(i);
  }
  dfs(0);
  cout << -1 << endl;
  return 0;
}
0