# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
237916 | 2020-06-09T09:45:11 Z | MrRobot_28 | ZigZag (COCI17_zigzag) | C++17 | 181 ms | 27260 KB |
#include<bits/stdc++.h> using namespace std; vector <vector <int> > hash1, hash2; vector <int> ind; vector <string> s; const int const1 = 1e9 + 7, const2 = 998244353; bool cmp(int a, int b) { int l = -1, r = min(hash1[a].size(), hash1[b].size()); while(r - l > 1) { int midd = (r + l) / 2; if(hash1[a][midd] == hash1[b][midd] && hash2[a][midd] == hash2[b][midd]) { l = midd; } else { r = midd; } } if(l == hash1[a].size()) { return true; } if(l == hash1[b].size()) { return false; } if(s[a][l + 1] < s[b][l + 1]) { return true; } else { return false; } } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, m; cin >> n >> m; hash1.resize(n); hash2.resize(n); ind.resize(n); s.resize(n); for(int i = 0; i < n; i++) { ind[i] = i; cin >> s[i]; hash1[i].resize(s[i].size()); hash2[i].resize(s[i].size()); for(int j = 0; j < s[i].size(); j++) { if(j == 0) { hash1[i][j] = hash2[i][j] = s[i][j] - 'a' + 1; } else { hash1[i][j] = (hash1[i][j - 1] * 27 + s[i][j] - 'a' + 1) % const1; hash2[i][j] = (hash2[i][j - 1] * 27 + s[i][j] - 'a' + 1) % const2; } } } vector <int> iter(26); vector <vector <int> > index(26); sort(ind.begin(), ind.end(), cmp); for(int i = 0; i < ind.size(); i++) { index[s[ind[i]][0] - 'a'].push_back(ind[i]); } while(m--){ char t; cin >> t; int j = iter[t - 'a'] % (int(index[t - 'a'].size())); cout << s[index[t - 'a'][j]] << "\n"; iter[t - 'a']++; } return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 384 KB | Output is correct |
2 | Correct | 5 ms | 384 KB | Output is correct |
3 | Correct | 5 ms | 512 KB | Output is correct |
4 | Correct | 5 ms | 512 KB | Output is correct |
5 | Correct | 5 ms | 512 KB | Output is correct |
6 | Correct | 5 ms | 512 KB | Output is correct |
7 | Correct | 181 ms | 27080 KB | Output is correct |
8 | Correct | 170 ms | 27260 KB | Output is correct |
9 | Correct | 154 ms | 27132 KB | Output is correct |
10 | Correct | 150 ms | 27128 KB | Output is correct |