CSES - E4590 2020 2 - Results
Submission details
Task:Swapping letters
Sender:kkivimaki
Submission time:2020-09-19 15:38:54 +0300
Language:C++ (C++11)
Status:READY
Result:
Test results
testverdicttime
#10.01 sdetails
#2ACCEPTED0.01 sdetails
#3ACCEPTED0.01 sdetails
#40.05 sdetails
#5ACCEPTED0.05 sdetails
#60.05 sdetails
#7ACCEPTED0.05 sdetails
#8--details
#9--details
#10--details

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:33:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < letters.size(); i++) {
                    ~~^~~~~~~~~~~~~~~~
input/code.cpp:34:22: warning: array subscript has type 'char' [-Wchar-subscripts]
         at[letters[i]] = 0;
                      ^
input/code.cpp:35:23: warning: array subscript has type 'char' [-Wchar-subscripts]
         prx[letters[i]] = 0;
                       ^
input/code.cpp:36:23: warning: array subscript has type 'char' [-Wchar-subscripts]
         pvx[letters[i]] = 0;
                       ^
input/code.cpp:37:23: warning: array subscript has type 'char' [-Wchar-subscripts]
         pry[letters[i]] = 0;
                       ^
input/code.cpp:38:23: warning: array subscript has type 'char' [-Wchar-subscripts]
         pvy[letters[i]] = 0;
                       ^
input/code.cpp:51:14: warning: array subscript has type 'char' [-Wchar-subscr...

Code

#include <vector>
#include <iostream>
#include <string>
std::vector<int> l0[1000];
int at[123];
int prx[123];
int pvx[123];
int pry[123];
int pvy[123];
std::string letters = "abcdefghijklmnopqrstuvwxyz";
int count(std::string s, char c, int a, int e) {
int n = 0;
for(int i = a; i < e; i++) {
if (s.c_str()[i] == c) n++;
}
return n;
}
int find(std::string y, int a, char c) {
int i = a;
while(1) {
if (y.c_str()[i] == c)
break;
i += 1;
}
return i;
}
int main() {
for(int i = 0; i < letters.size(); i++) {
at[letters[i]] = 0;
prx[letters[i]] = 0;
pvx[letters[i]] = 0;
pry[letters[i]] = 0;
pvy[letters[i]] = 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 x;
std::string y;
std::cin >> x;
std::cin >> y;
int i = 0;
for(int i = 0; i < x.size(); i++) {
//std::cout << i << " " << x.size() << std::endl;
char c = x.c_str()[i];
int j = find(y, at[c], c);
at[c] = j + 1;
for (int r : l0[c]) {
/*
int cx = count(x, r, pvx[c], i);
pvx[c] = i + 1;
prx[c] += cx;
cx = prx[c];
*/
int cx = prx[r];
int cy = count(y, r, pvy[c], j);
pvy[c] = j + 1;
pry[c] += cy;
cy = pry[c];
if (cx != cy) {
std::cout << "NO" << std::endl;
return 0;
}
}
prx[c] += 1;
}
std::cout << "YES" << std::endl;
return 0;
}

Test details

Test 1

Verdict:

input
5
a b
b c
c d
d e
...

correct output
YES

user output
NO

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:

input
10
d c
e b
f y
h q
...

correct output
YES

user output
NO

Test 5

Verdict: ACCEPTED

input
10
a i
a l
d a
g h
...

correct output
NO

user output
NO

Test 6

Verdict:

input
325
a b
a e
a f
a g
...

correct output
YES

user output
NO

Test 7

Verdict: ACCEPTED

input
325
a c
a e
a g
a h
...

correct output
NO

user output
NO

Test 8

Verdict:

input
0
dlkinfmdyjaofxbccwhhbxzartqwdr...

correct output
YES

user output
(empty)

Test 9

Verdict:

input
0
bxisdrdpgcsnnvhnfgimivzqpqjwqc...

correct output
NO

user output
(empty)

Test 10

Verdict:

input
0
mrwduerojcguvxzmbomfsainvqehsl...

correct output
NO

user output
(empty)