# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
237916 | MrRobot_28 | ZigZag (COCI17_zigzag) | C++17 | 181 ms | 27260 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |