답안 #1087862

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1087862 2024-09-13T10:29:23 Z idk__ Xor Sort (eJOI20_xorsort) C++14
0 / 100
0 ms 348 KB
#include <bits/stdc++.h>
using namespace std;


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, t;
    cin >> n >> t;
    int a[n];
    for(int i = 0;i < n; i++){
        cin >> a[i];
    }
    //3 2 8 4 1
    //1 2 8 12 13
    if(t==1){
        vector<pair<int, int>>op;

        for(int i = 0;i < n-1; i++){
            if(a[i+1] <= a[i]){
                int nw = (a[i+1]^a[i]);
                if(a[i+1] > nw){
                    a[i] = nw;
                    op.push_back({i, i+1});
                }
                else if(a[i] < nw){
                    a[i+1]=nw;
                    op.push_back({i+1, i});
                }
            }
        }
        cout << op.size() << endl;
        for(auto [i, j] : op)cout << i+1 << " " << j+1 << endl;
    }
    else{
        vector<pair<int, int>>op;

        for(int i = 0;i < n-1; i++){
            if(a[i+1] < a[i]){
                int nw = (a[i+1]^a[i]);
                if(a[i+1] >= nw){
                    a[i] = nw;
                    op.push_back({i, i+1});
                }
                else if(a[i] <= nw){
                    a[i+1]=nw;
                    op.push_back({i+1, i});
                }
            }
        }
        cout << op.size() << endl;
        for(auto [i, j] : op)cout << i+1 << " " << j+1 << endl;
    }
    
    }

Compilation message

xorsort.cpp: In function 'int main()':
xorsort.cpp:34:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   34 |         for(auto [i, j] : op)cout << i+1 << " " << j+1 << endl;
      |                  ^
xorsort.cpp:53:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   53 |         for(auto [i, j] : op)cout << i+1 << " " << j+1 << endl;
      |                  ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Not sorted
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Not sorted
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Not sorted
2 Halted 0 ms 0 KB -