CSES - Datatähti 2021 loppu - Results
Submission details
Task:Järjestäminen
Sender:Guuber
Submission time:2021-01-23 18:34:28 +0200
Language:C++ (C++17)
Status:READY
Result:36
Feedback
groupverdictscore
#1ACCEPTED36
#20
Test results
testverdicttimegroup
#1ACCEPTED0.19 s1, 2details
#20.19 s2details
#3ACCEPTED0.19 s1, 2details
#4ACCEPTED0.19 s1, 2details

Compiler report

input/code.cpp: In function 'void haku(std::__cxx11::string, int)':
input/code.cpp:10:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < s.size()-1; i++){
                 ~~^~~~~~~~~~~~
input/code.cpp:11:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int j = 0; j < s.size()-1; j++){
                  ~~^~~~~~~~~~~~

Code

#include<bits/stdc++.h>
using namespace std;

map<string,int> ma[11];

void haku(string s, int d){
	if(ma[d][s]) return;
	ma[d][s] = 1;
//	cout << s << "\n";
	for(int i = 0; i < s.size()-1; i++){
		for(int j = 0; j < s.size()-1; j++){
			if(i == j || i+1 == j || j+1 == i || i+1 == j+1) continue;
			swap(s[i], s[j]);
			swap(s[i+1], s[j+1]);
			haku(s, d);
			swap(s[i], s[j]);
			swap(s[i+1], s[j+1]);
		}
	}
}

int main(){
	int t;
	cin >> t;


	for(int i = 1; i <= 8; i++){
		string s = "";
		for(int j = 0; j < i; j++){
			s += (char)(j+1+'0');
		}
		//cout << s << "\n";
	//	return 0;
		haku(s, i);
		for(auto u : ma[i]){
//			cout << i << ": " << u.first << "\n";
		}
	}
	while(t--){
		int n;
		cin >> n;
		string s = "";
	//	for(auto u : ma[n]) //cout << u.first << "\n";
		for(int i = 0; i < n; i++){
			char a;
			cin >> a;
			s += a;
		}
		if(ma[n][s]) cout << "YES\n";
		else cout << "NO\n";
	}
}

Test details

Test 1

Group: 1, 2

Verdict: ACCEPTED

input
153
1
1
2
1 2
...

correct output
YES
YES
NO
NO
NO
...

user output
YES
YES
NO
NO
NO
...
Truncated

Test 2

Group: 2

Verdict:

input
1000
59
35 29 32 50 11 15 9 21 19 45 2...

correct output
YES
NO
YES
NO
YES
...

user output
(empty)

Test 3

Group: 1, 2

Verdict: ACCEPTED

input
720
6
1 6 4 5 2 3
6
6 3 2 1 5 4
...

correct output
YES
NO
NO
NO
YES
...

user output
YES
NO
NO
NO
YES
...
Truncated

Test 4

Group: 1, 2

Verdict: ACCEPTED

input
1000
8
7 4 2 8 6 3 5 1
8
3 8 2 7 5 4 6 1
...

correct output
NO
NO
YES
NO
YES
...

user output
NO
NO
YES
NO
YES
...
Truncated