| Task: | Swapping letters |
| Sender: | kkivimaki |
| Submission time: | 2020-09-19 14:59:48 +0300 |
| Language: | C++ (C++11) |
| Status: | READY |
| Result: | TIME LIMIT EXCEEDED |
| test | verdict | time | |
|---|---|---|---|
| #1 | ACCEPTED | 0.01 s | details |
| #2 | ACCEPTED | 0.01 s | details |
| #3 | ACCEPTED | 0.01 s | details |
| #4 | TIME LIMIT EXCEEDED | -- | details |
| #5 | TIME LIMIT EXCEEDED | -- | details |
| #6 | TIME LIMIT EXCEEDED | -- | details |
| #7 | TIME LIMIT EXCEEDED | -- | details |
| #8 | TIME LIMIT EXCEEDED | -- | details |
| #9 | TIME LIMIT EXCEEDED | -- | details |
| #10 | TIME LIMIT EXCEEDED | -- | details |
Compiler report
input/code.cpp: In function 'int count(std::__cxx11::string, char)':
input/code.cpp:14:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < s.size(); i++) {
~~^~~~~~~~~~
input/code.cpp: In function 'int main()':
input/code.cpp:36:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < letters.size(); i++) {
~~^~~~~~~~~~~~~~~~
input/code.cpp:37:21: warning: array subscript has type 'char' [-Wchar-subscripts]
f[letters[i]] = 1;
^
input/code.cpp:50:14: warning: array subscript has type 'char' [-Wchar-subscripts]
l0[c0].push_back(c1);
^
input/code.cpp:51:14: warning: array subscript has type 'char' [-Wchar-subscripts]
l0[c1].push_back(c0);
^
input/code.cpp:66:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i...Code
#include <vector>
#include <iostream>
#include <string>
std::vector<int> l0[1000];
int f[1000];
std::string letters = "abcdefghijklmnopqrstuvwxyz";
int count(std::string s, char c) {
//std::cout << "Looking for " << c << " from " << s << std::endl;
int n = 0;
for(int i = 0; i < s.size(); i++) {
if (s.c_str()[i] == c) n++;
}
//std::cout << "Found " << n << std::endl;
return n;
}
int find(std::string y, char c, int m) {
//std::cout << "\tind " << c << " " << m << " " << y << std::endl;
int i = 0;
while(1) {
if (y.c_str()[i] == c) {
m -= 1;
if (m <= 0) break;
}
i += 1;
}
//std::cout << i << std::endl;
return i;
}
int main() {
for(int i = 0; i < letters.size(); i++) {
f[letters[i]] = 1;
}
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;
//if sorted(x) != sorted(y):
// print("NO")
// return
int i = 0;
for(int i = 0; i < x.size(); i++) {
char c = x.c_str()[i];
int j = find(y, c, f[c]);
for (int r : l0[c]) {
std::string s0 = std::string(x, 0, i);
std::string s1 = std::string(y, 0, j);
if (count(s0, r) != count(s1, r)) {
//std::cout << r << std::endl;
//std::cout << "s0 " << s0 << std::endl;
//std::cout << "s1 " << s1 << std::endl;
//std::cout << c << std::endl;
//std::cout << i << std::endl;
std::cout << "NO" << std::endl;
return 0;
}
}
f[c] += 1;
}
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: TIME LIMIT EXCEEDED
| input |
|---|
| 10 d c e b f y h q ... |
| correct output |
|---|
| YES |
| user output |
|---|
| (empty) |
Test 5
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 10 a i a l d a g h ... |
| correct output |
|---|
| NO |
| user output |
|---|
| (empty) |
Test 6
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 325 a b a e a f a g ... |
| correct output |
|---|
| YES |
| user output |
|---|
| (empty) |
Test 7
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 325 a c a e a g a h ... |
| correct output |
|---|
| NO |
| user output |
|---|
| (empty) |
Test 8
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 0 dlkinfmdyjaofxbccwhhbxzartqwdr... |
| correct output |
|---|
| YES |
| user output |
|---|
| (empty) |
Test 9
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 0 bxisdrdpgcsnnvhnfgimivzqpqjwqc... |
| correct output |
|---|
| NO |
| user output |
|---|
| (empty) |
Test 10
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 0 mrwduerojcguvxzmbomfsainvqehsl... |
| correct output |
|---|
| NO |
| user output |
|---|
| (empty) |
