Task: | Swapping letters |
Sender: | kkivimaki |
Submission time: | 2020-09-19 16:17:58 +0300 |
Language: | C++ (C++11) |
Status: | READY |
Result: | ACCEPTED |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.01 s | details |
#2 | ACCEPTED | 0.01 s | details |
#3 | ACCEPTED | 0.01 s | details |
#4 | ACCEPTED | 0.15 s | details |
#5 | ACCEPTED | 0.09 s | details |
#6 | ACCEPTED | 0.91 s | details |
#7 | ACCEPTED | 0.05 s | details |
#8 | ACCEPTED | 0.12 s | details |
#9 | ACCEPTED | 0.11 s | details |
#10 | ACCEPTED | 0.11 s | details |
Compiler report
input/code.cpp: In function 'int main()': input/code.cpp:35:14: warning: array subscript has type 'char' [-Wchar-subscripts] l0[c0].push_back(c1); ^ input/code.cpp:36:14: warning: array subscript has type 'char' [-Wchar-subscripts] l0[c1].push_back(c0); ^ input/code.cpp:53:29: warning: array subscript has type 'char' [-Wchar-subscripts] int j = find(y, at[c], c); ^ input/code.cpp:54:13: warning: array subscript has type 'char' [-Wchar-subscripts] at[c] = j + 1; ^ input/code.cpp:56:26: warning: array subscript has type 'char' [-Wchar-subscripts] for (int r : l0[c]) { ^ input/code.cpp:61:26: warning: array subscript has type 'char' [-Wchar-subscripts] for(a = pvy[c][r]; y[a] != c; a++) ^ input/code.cpp:64:18: warning: array subscript has type 'char' [-Wchar-subscripts] pvy[c][r] = a + 1;...
Code
#include <vector> #include <iostream> #include <string> std::vector<int> l0[1000]; int at[123]; int prx[123]; int pry[123][123]; int pvy[123][123]; int find(const char* y, int a, char c) { int i = a; while(y[i] != c) i++; return i; } int main() { for(int i = 0; i < 123; i++) { for(int j = 0; j < 123; j++) { pvy[i][j] = 0; pry[i][j] = 0; } } int n; std::cin >> n; while (n > 0) { n -= 1; char c0; char c1; std::cin >> c0; std::cin >> c1; l0[c0].push_back(c1); l0[c1].push_back(c0); } std::string x0; std::string y0; std::cin >> x0; std::cin >> y0; int N = x0.size(); const char* x = x0.c_str(); const char* y = y0.c_str(); int i = 0; for(int i = 0; i < N; i++) { char c = x[i]; int j = find(y, at[c], c); at[c] = j + 1; for (int r : l0[c]) { int cx = prx[r]; int n = 0; int a; for(a = pvy[c][r]; y[a] != c; a++) if (y[a] == r) n++; pvy[c][r] = a + 1; pry[c][r] += n; int cy = pry[c][r]; if (cx != cy) { std::cout << "NO" << std::endl; return 0; } } prx[c] += 1; } for(int c = 97; c <= 122; c++) { int n = 0; int m = 0; for(int i = 0; i < N; i++) { n += x[i] == c; m += y[i] == c; } if (n != m) { std::cout << "NO" << std::endl; return 0; } } std::cout << "YES" << std::endl; return 0; }
Test details
Test 1
Verdict: ACCEPTED
input |
---|
5 a b b c c d d e ... |
correct output |
---|
YES |
user output |
---|
YES |
Test 2
Verdict: ACCEPTED
input |
---|
2 a b b c acbbaca cabbaac |
correct output |
---|
YES |
user output |
---|
YES |
Test 3
Verdict: ACCEPTED
input |
---|
2 a b b c acbbaca baccaab |
correct output |
---|
NO |
user output |
---|
NO |
Test 4
Verdict: ACCEPTED
input |
---|
10 d c e b f y h q ... |
correct output |
---|
YES |
user output |
---|
YES |
Test 5
Verdict: ACCEPTED
input |
---|
10 a i a l d a g h ... |
correct output |
---|
NO |
user output |
---|
NO |
Test 6
Verdict: ACCEPTED
input |
---|
325 a b a e a f a g ... |
correct output |
---|
YES |
user output |
---|
YES |
Test 7
Verdict: ACCEPTED
input |
---|
325 a c a e a g a h ... |
correct output |
---|
NO |
user output |
---|
NO |
Test 8
Verdict: ACCEPTED
input |
---|
0 dlkinfmdyjaofxbccwhhbxzartqwdr... |
correct output |
---|
YES |
user output |
---|
YES |
Test 9
Verdict: ACCEPTED
input |
---|
0 bxisdrdpgcsnnvhnfgimivzqpqjwqc... |
correct output |
---|
NO |
user output |
---|
NO |
Test 10
Verdict: ACCEPTED
input |
---|
0 mrwduerojcguvxzmbomfsainvqehsl... |
correct output |
---|
NO |
user output |
---|
NO |