結果

問題 No.2148 ひとりUNO
ユーザー beetbeet
提出日時 2022-12-03 14:51:12
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 74 ms / 2,000 ms
コード長 1,479 bytes
コンパイル時間 3,002 ms
コンパイル使用メモリ 221,424 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-20 04:59:11
合計ジャッジ時間 5,317 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 7 ms
5,248 KB
testcase_02 AC 7 ms
5,376 KB
testcase_03 AC 7 ms
5,376 KB
testcase_04 AC 7 ms
5,376 KB
testcase_05 AC 7 ms
5,376 KB
testcase_06 AC 7 ms
5,376 KB
testcase_07 AC 7 ms
5,376 KB
testcase_08 AC 7 ms
5,376 KB
testcase_09 AC 7 ms
5,376 KB
testcase_10 AC 7 ms
5,376 KB
testcase_11 AC 7 ms
5,376 KB
testcase_12 AC 7 ms
5,376 KB
testcase_13 AC 7 ms
5,376 KB
testcase_14 AC 7 ms
5,376 KB
testcase_15 AC 7 ms
5,376 KB
testcase_16 AC 73 ms
5,376 KB
testcase_17 AC 73 ms
5,376 KB
testcase_18 AC 73 ms
5,376 KB
testcase_19 AC 74 ms
5,376 KB
testcase_20 AC 72 ms
5,376 KB
testcase_21 AC 73 ms
5,376 KB
testcase_22 AC 70 ms
5,376 KB
testcase_23 AC 72 ms
5,376 KB
testcase_24 AC 72 ms
5,376 KB
testcase_25 AC 71 ms
5,376 KB
testcase_26 AC 19 ms
5,376 KB
testcase_27 AC 20 ms
5,376 KB
testcase_28 AC 19 ms
5,376 KB
testcase_29 AC 20 ms
5,376 KB
testcase_30 AC 20 ms
5,376 KB
testcase_31 AC 20 ms
5,376 KB
testcase_32 AC 20 ms
5,376 KB
testcase_33 AC 20 ms
5,376 KB
testcase_34 AC 20 ms
5,376 KB
testcase_35 AC 19 ms
5,376 KB
testcase_36 AC 18 ms
5,376 KB
testcase_37 AC 18 ms
5,376 KB
testcase_38 AC 18 ms
5,376 KB
testcase_39 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using Int = long long;
const char newl = '\n';

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);}
template<typename T=int>
vector<T> read(size_t n){
  vector<T> ts(n);
  for(size_t i=0;i<n;i++) cin>>ts[i];
  return ts;
}

//INSERT ABOVE HERE
signed solve(){
  int n;
  cin>>n;
  map<string, set<int>> mp;
  for(int i=0;i<n;i++){
    string c;
    int d;
    cin>>c>>d;
    mp[c].emplace(d);
  }
  vector<string> ks;
  for(auto&[k,v]:mp) ks.emplace_back(k);
  sort(ks.begin(),ks.end());

  if(ks.size()==1){
    cout<<"YES"<<newl;
    return 0;
  }

  int ok=0;
  do{
    int ng=0;
    auto cur=mp[ks[0]];
    for(int i=1;i<(int)ks.size();i++){
      auto nxt=mp[ks[i]];
      set<int> intersection;
      for(int l:cur)
        if(nxt.count(l))
          intersection.emplace(l);

      if(intersection.size()==0){
        ng=1;
        break;
      }

      if(intersection.size()==1){
        if(nxt.size()!=1){
          nxt.erase(*intersection.begin());
        }
        cur=nxt;
        continue;
      }

      cur=nxt;
    }
    if(!ng) ok=1;
  }while(next_permutation(ks.begin(),ks.end()));
  cout<<(ok?"YES":"NO")<<newl;
  return 0;
}

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

  int t;
  cin>>t;
  while(t--) solve();

  return 0;
}
0