tuki2501

bedao_r03_wordgame.cpp

Nov 28th, 2021
508
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. typedef long long ll;
  5.  
  6. signed main() {
  7.   cin.tie(0)->sync_with_stdio(0);
  8.   int n; cin >> n;
  9.   vector<string> a(n);
  10.   for (auto &i : a) {
  11.     cin >> i;
  12.   }
  13.   unordered_set<string> s;
  14.   s.insert(a[0]);
  15.   for (int i = 1; i < n; i++) {
  16.     if (a[i].front() != a[i - 1].back() || s.count(a[i])) {
  17.       cout << "NO" << '\n';
  18.       cout << i + 1 << '\n';
  19.       return 0;
  20.     }
  21.     s.insert(a[i]);
  22.   }
  23.   cout << "YES" << '\n';
  24. }
  25.  
RAW Paste Data