Submission #1244208


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;
			if (i == a.length() || j == b.length()) {
				break;
			}
		}
		if (i == a.length() || j == b.length()) {
			return a.length() < b.length();
		} else {
			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) {

	ios::sync_with_stdio(false);

	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 1762 Byte
Status TLE
Exec Time 6305 ms
Memory 24740 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 1100
Status
AC × 2
AC × 5
TLE × 37
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 22692 KB
02.txt TLE 6305 ms 22692 KB
03.txt TLE 6305 ms 22692 KB
04.txt TLE 6305 ms 22692 KB
05.txt TLE 6304 ms 19492 KB
06.txt TLE 6303 ms 19876 KB
07.txt TLE 6304 ms 17700 KB
08.txt TLE 6303 ms 19748 KB
09.txt TLE 6304 ms 17828 KB
10.txt TLE 6303 ms 20004 KB
11.txt TLE 6304 ms 18980 KB
12.txt TLE 6303 ms 21668 KB
13.txt TLE 6303 ms 22564 KB
14.txt TLE 6304 ms 17828 KB
15.txt TLE 6304 ms 20004 KB
16.txt TLE 6304 ms 17908 KB
17.txt AC 272 ms 17844 KB
18.txt TLE 6303 ms 19748 KB
19.txt TLE 6304 ms 17700 KB
20.txt TLE 6303 ms 19748 KB
21.txt TLE 6304 ms 17700 KB
22.txt TLE 6303 ms 19748 KB
23.txt TLE 6304 ms 19364 KB
24.txt TLE 6304 ms 18980 KB
25.txt TLE 6304 ms 19620 KB
26.txt TLE 6304 ms 17700 KB
27.txt TLE 6304 ms 17828 KB
28.txt TLE 6304 ms 17956 KB
29.txt TLE 6304 ms 17700 KB
30.txt TLE 6304 ms 18468 KB
31.txt TLE 6304 ms 17700 KB
32.txt TLE 6304 ms 17828 KB
33.txt TLE 6304 ms 17828 KB
34.txt TLE 6304 ms 17828 KB
35.txt TLE 6304 ms 17700 KB
36.txt TLE 6304 ms 24740 KB
37.txt TLE 6304 ms 18104 KB
38.txt TLE 6304 ms 20152 KB
39.txt AC 1 ms 256 KB
40.txt AC 1 ms 256 KB
s1.txt AC 1 ms 256 KB
s2.txt AC 1 ms 256 KB