Submission #606988

# Submission time Handle Problem Language Result Execution time Memory
606988 2022-07-26T10:57:04 Z 1bin Shift (POI11_prz) C++14
0 / 100
380 ms 25164 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; 
                
            for(int i = 0; i < n; i++) cout << a[i] << ' ';
            cout << '\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 Incorrect 1 ms 212 KB Expected EOF
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Expected EOF
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Expected EOF
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 596 KB Expected EOF
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 24 ms 1788 KB Expected EOF
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 262 ms 15928 KB Expected EOF
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 314 ms 20428 KB Expected EOF
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 380 ms 25164 KB Expected EOF
2 Halted 0 ms 0 KB -