Submission #606993

# Submission time Handle Problem Language Result Execution time Memory
606993 2022-07-26T11:00:43 Z 1bin Shift (POI11_prz) C++14
88 / 100
163 ms 14344 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 & 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:72:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   72 |         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 248 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Failed 0 ms 212 KB Wrong operation
6 Halted 0 ms 0 KB -
# 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
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 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 340 KB Output is correct
2 Correct 2 ms 468 KB Output is correct
3 Correct 2 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 828 KB Output is correct
2 Correct 7 ms 840 KB Output is correct
3 Correct 7 ms 856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 66 ms 4864 KB Output is correct
2 Correct 62 ms 4924 KB Output is correct
3 Correct 62 ms 4752 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 78 ms 6012 KB Output is correct
2 Correct 82 ms 6144 KB Output is correct
3 Correct 82 ms 5872 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 113 ms 7212 KB Output is correct
2 Correct 105 ms 7316 KB Output is correct
3 Correct 163 ms 14344 KB Output is correct
4 Correct 12 ms 368 KB Output is correct
5 Correct 2 ms 340 KB Output is correct