結果
| 問題 |
No.2102 [Cherry Alpha *] Conditional Reflection
|
| コンテスト | |
| ユーザー |
Nachia
|
| 提出日時 | 2022-10-15 03:10:33 |
| 言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 632 ms / 3,000 ms |
| コード長 | 2,063 bytes |
| コンパイル時間 | 8,020 ms |
| コンパイル使用メモリ | 167,424 KB |
| 最終ジャッジ日時 | 2025-02-08 06:04:25 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 70 |
ソースコード
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
#include <set>
#include <atcoder/string>
using namespace std;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using u128 = __uint128_t;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
int main(){
int N; cin >> N;
vector<string> S(N); rep(i,N) cin >> S[i];
vector<vector<int>> I(1000001);
rep(i,N) I[S[i].size()].push_back(i);
vector<int> ans(N, 0);
rep(L,I.size()) if(L>=3) if(!I[L].empty()){
string s;
for(auto& i : I[L]){ s += S[i].substr(2); s += S[i].substr(0, L-2); }
auto sa = atcoder::suffix_array(s);
auto lcp = atcoder::lcp_array(s, sa);
map<pair<int, int>, int> Q;
rep(i,sa.size()){
if(i != 0) if(lcp[i-1] < L-2) Q.clear();
int c = sa[i] / (L*2-4), p = sa[i] % (L*2-4);
if(p >= L-1) continue;
int si = I[L][c];
int c1 = S[si][p], c2 = S[si][p+1];
pair<int, int> key = { p, max(c1,c2)*1000+min(c1,c2) };
if(Q.count(key)){
int& v = Q[key];
ans[max(v, si)] = 1; v = min(v, si);
} else Q.insert({ key, si });
}
}
rep(L,I.size()){
if(L==1){
map<string, int> Q;
for(int i : I[L]) /* I[L] sorted */ {
if(Q.count(S[i])) ans[i] = 1; else Q[S[i]] = i;
}
}
if(L==2){
map<int, int> Q;
for(int i : I[L]) /* I[L] sorted */ {
int c1 = S[i][0], c2 = S[i][1];
int key = max(c1,c2)*1000+min(c1,c2);
if(Q.count(key)) ans[i] = 1; else Q[key] = i;
}
}
}
vector<int> vis(N);
rep(i,N){
cout << (ans[i] ? "Yes\n" : "No\n");
}
return 0;
}
struct ios_do_not_sync{
ios_do_not_sync(){
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
}
} ios_do_not_sync_instance;
Nachia