# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
606996 |
2022-07-26T11:03:58 Z |
1bin |
Shift (POI11_prz) |
C++14 |
|
164 ms |
14264 KB |
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
typedef long long ll;
const int NMAX = 2e3 + 5;
int n, a[NMAX], ix[NMAX], cnt, s, x;
vector<int> v;
void flsh(){
v.emplace_back(1);
v.emplace_back(3);
v.emplace_back(n - 1);
}
void move(int x, int cnt){
while(cnt){
if(cnt == 1) {
if(ix[a[x]] == 1) flsh();
else v.emplace_back((-ix[a[x]] + 1 + n) % n);
swap(a[x - 1], a[x]);
swap(a[x], a[x + 1]);
cnt--; ix[a[x]] = 0;
v.emplace_back(2);
}
else{
if(ix[a[x]] == 2) flsh();
else v.emplace_back((-ix[a[x]] + 2 + n) % n);
swap(a[x - 1], a[x]); x--;
swap(a[x - 1], a[x]); x--;
cnt -= 2; ix[a[x]] = 0;
v.emplace_back(1);
}
}
return;
}
int main(void){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n;
for(int i = 0; i < n; i++){
cin >> a[i]; a[i]--;
for(int j = 0; j < i; j++)
if(a[j] > a[i]) cnt++;
}
if(n == 2) {
if(a[0] == 1) v.emplace_back(1);
}
else if(n & 1 && cnt & 1) cout << "NIE DA SIE";
else{
if(cnt & 1) {
x = a[n - 1];
for(int i = n - 1; i; i--) a[i] = a[i - 1];
a[0] = x;
v.emplace_back(1);
v.emplace_back(3);
}
for(int i = 0; i < n; i++) ix[a[i]] = i;
for(int i = 0; i < n; i++){
if(a[i] == i) continue;
for(int j = 0; j < n; j++)
if(a[j] == i) move(j, j - i);
for(int j = 0; j < n; j++) ix[a[j]] = (j + n - i) % n;
}
if(ix[0]) v.emplace_back(n - ix[0]);
cout << v.size() << '\n';
for(int i = 0; i < v.size(); i++){
if(i & 1) cout << v[i] << "b ";
else cout << v[i] << "a ";
}
}
return 0;
}
Compilation message
prz.cpp: In function 'int main()':
prz.cpp:75:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
75 | for(int i = 0; i < v.size(); i++){
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Incorrect |
0 ms |
212 KB |
Unexpected end of file - int32 expected |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
272 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
868 KB |
Output is correct |
2 |
Correct |
6 ms |
856 KB |
Output is correct |
3 |
Correct |
7 ms |
856 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
67 ms |
4872 KB |
Output is correct |
2 |
Correct |
62 ms |
4852 KB |
Output is correct |
3 |
Correct |
64 ms |
4792 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
80 ms |
6072 KB |
Output is correct |
2 |
Correct |
80 ms |
6036 KB |
Output is correct |
3 |
Correct |
78 ms |
5944 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
97 ms |
7256 KB |
Output is correct |
2 |
Correct |
97 ms |
7392 KB |
Output is correct |
3 |
Correct |
164 ms |
14264 KB |
Output is correct |
4 |
Correct |
12 ms |
340 KB |
Output is correct |
5 |
Correct |
3 ms |
212 KB |
Output is correct |