| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1353434 | thuhienne | Ispit (COCI19_ispit) | C++20 | 0 ms | 0 KiB |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define thuhien ""
#define re exit(0);
#define hash __hash__
#define count __count__
const ll mod = 1e9 + 7;
const ll base = 31;
int n,k;
string s[509];
int cnt[509][29];
bool marked[509];
int count;
vector <int> group[509];
vector <pair <ll,int>> ff;
ll hash[509],revhash[509];
ll comb(int a,int b) {
return ((1ll * a) << 31) + b;
}
void solve(vector <int> index) {
ff.clear();
for (int i : index) {
for (int j = 1;j <= n;j++) {
hash[j] = (hash[j - 1] * base + s[i][j] - 'a' + 1) % mod;
}
for (int j = n;j >= 1;j--) {
revhash[j] = (revhash[j + 1] * base + s[i][j] - 'a' + 1) % mod;
}
for (int j = 1;j + k - 1 <= n;j++) {
ff.push_back({comb(hash[j - 1],revhash[j + k]),i});
}
}
sort(ff.begin(),ff.end());
for (int i = 1;i < ff.size();i++) {
if (ff[i - 1].first == ff[i].first && ff[i - 1].second != ff[i].second) {
// for (int j : index) cout << s[j] << '\n';
cout << "DA";
re;
}
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(nullptr);
if (fopen(thuhien".inp","r")) {
freopen(thuhien".inp","r",stdin);
freopen(thuhien".out","w",stdout);
}
cin >> n >> k;
for (int i = 1;i <= n;i++) {
cin >> s[i];
s[i] = " " + s[i];
for (int j = 1;j <= n;j++) cnt[i][s[i][j] - 'a']++;
}
for (int i = 1;i <= n;i++) if (!marked[i]) {
marked[i] = 1;
group[++count].push_back(i);
for (int j = i + 1;j <= n;j++) if (!marked[j]) {
bool cmp = 1;
for (int k = 0;k < 26;k++) if (cnt[i][k] != cnt[j][k]) {
cmp = 0;
break;
}
if (cmp) {
marked[j] = 1;
group[count].push_back(j);
}
}
}
for (int i = 1;i <= count;i++) solve(group[i]);
cout << "NE";
}
컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
