Submission #1244176
Source Code Expand
#include <algorithm> #include <iostream> #include <vector> #include <string> #include <unordered_map> using namespace std; unordered_map<char, int> currentOrder; struct comp { bool operator() (string a, string b) { int i = 0, j = 0; while (a[i] == b[j]) { ++i; ++j; } return currentOrder[a[i]] < currentOrder[b[j]]; } } comp; int find(vector<string> &str, string s) { int l = 0, r = str.size() - 1; while (l < r) { int mid = (l + r) / 2; if (comp(str[mid], s)) { l = mid + 1; } else { r = mid; } } return l; } int main(void) { int n; cin >> n; vector<string> str(n); for (int i = 0; i < n; ++i) { cin >> str[i]; } int q; cin >> q; vector<int> result(q, -1); unordered_map< string, vector< pair<string, int> > > table; for (int i = 0; i < q; ++i) { int idx; string order; cin >> idx >> order; table[order].push_back(make_pair(str[idx - 1], i)); } unordered_map< string, vector< pair<string, int> > >::iterator iter; for (iter = table.begin(); iter != table.end(); ++iter) { string order = iter->first; for (int i = 0; i < 26; ++i) { currentOrder[order[i]] = i; } sort(str.begin(), str.end(), comp); /* for (int i = 0; i < str.size(); ++i) { cout << str[i] << endl; } cout << endl; */ for (int i = 0; i < iter->second.size(); ++i) { result[iter->second[i].second] = find(str, iter->second[i].first) + 1; } // break; } for (int i = 0; i < q; ++i) { cout << result[i] << endl; } return 0; }
Submission Info
Submission Time | |
---|---|
Task | E - Lexicographical disorder |
User | indcn20171018 |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 1568 Byte |
Status | WA |
Exec Time | 6305 ms |
Memory | 24228 KB |
Judge Result
Set Name | Sample | All | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 1100 | ||||||||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | s1.txt, s2.txt |
All | 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, 35.txt, 36.txt, 37.txt, 38.txt, 39.txt, 40.txt, s1.txt, s2.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
01.txt | TLE | 6305 ms | 24228 KB |
02.txt | TLE | 6305 ms | 24228 KB |
03.txt | TLE | 6305 ms | 24228 KB |
04.txt | TLE | 6305 ms | 24228 KB |
05.txt | TLE | 6305 ms | 21668 KB |
06.txt | TLE | 6304 ms | 19492 KB |
07.txt | TLE | 6304 ms | 19364 KB |
08.txt | TLE | 6304 ms | 19236 KB |
09.txt | TLE | 6304 ms | 19492 KB |
10.txt | TLE | 6304 ms | 19364 KB |
11.txt | TLE | 6305 ms | 20900 KB |
12.txt | TLE | 6305 ms | 21668 KB |
13.txt | TLE | 6304 ms | 24100 KB |
14.txt | TLE | 6303 ms | 21540 KB |
15.txt | TLE | 6303 ms | 21540 KB |
16.txt | TLE | 6304 ms | 21412 KB |
17.txt | AC | 402 ms | 19356 KB |
18.txt | TLE | 6304 ms | 19364 KB |
19.txt | TLE | 6303 ms | 21412 KB |
20.txt | TLE | 6304 ms | 19364 KB |
21.txt | TLE | 6304 ms | 21412 KB |
22.txt | TLE | 6304 ms | 21412 KB |
23.txt | TLE | 6305 ms | 21540 KB |
24.txt | TLE | 6304 ms | 22948 KB |
25.txt | TLE | 6304 ms | 23716 KB |
26.txt | TLE | 6303 ms | 21412 KB |
27.txt | TLE | 6303 ms | 21540 KB |
28.txt | TLE | 6303 ms | 21796 KB |
29.txt | TLE | 6303 ms | 21412 KB |
30.txt | TLE | 6303 ms | 22436 KB |
31.txt | TLE | 6304 ms | 19492 KB |
32.txt | TLE | 6304 ms | 19492 KB |
33.txt | TLE | 6304 ms | 19364 KB |
34.txt | TLE | 6304 ms | 19364 KB |
35.txt | TLE | 6304 ms | 19364 KB |
36.txt | TLE | 6305 ms | 24228 KB |
37.txt | TLE | 6304 ms | 19628 KB |
38.txt | TLE | 6304 ms | 19628 KB |
39.txt | WA | 1 ms | 256 KB |
40.txt | AC | 1 ms | 256 KB |
s1.txt | WA | 1 ms | 256 KB |
s2.txt | AC | 1 ms | 256 KB |