답안 #745588

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
745588 2023-05-20T14:12:26 Z lukadupli Nizovi (COI14_nizovi) C++14
80 / 100
243 ms 280 KB
#include <bits/stdc++.h>

#define f first
#define s second

using namespace std;

typedef pair<int, int> pii;

bool cmp(int a, int b){
    cout << "cmp " << a << ' ' << b << endl;
    int x;
    cin >> x;
    return x == -1;
}
void rev(int l, int r){
    if(l == r) return;
    cout << "reverse " << l << ' ' << r << endl;
}

int A, B;

void solve(int pos, int fall){
    //cout << "solving: " << pos << ' ' << fall << '\n';
    if(pos >= A + B || fall > A + B || pos >= fall) return;

    if(cmp(pos, fall)){
        int l = pos + 1, r = fall - 1;
        while(r > l){
            int m = (l + r) / 2;

            if(!cmp(m, fall)) r = m;
            else l = m + 1;
        }

        if(l == fall - 1 && cmp(l, fall)) return;

        pos = l;
    }
    //cout << "adjusted to: " << pos << ' ' << fall << '\n';
    if(pos >= A + B || fall > A + B || pos >= fall) return;

    int l = fall, r = A + B;
    while(r > l){
        int m = (l + r + 1) / 2;

        if(cmp(m, pos)) l = m;
        else r = m - 1;
    }

    rev(pos, l);
    rev(pos, pos + l - fall);
    rev(pos + l - fall + 1, l);

    solve(pos + l - fall + 1, l + 1);
}

int main()
{
    cin >> A >> B;
    solve(1, A + 1);

    cout << "end" << endl;

	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 2 ms 208 KB Output is correct
3 Correct 4 ms 208 KB Output is correct
4 Correct 67 ms 208 KB Output is correct
5 Correct 22 ms 208 KB Output is correct
6 Correct 29 ms 208 KB Output is correct
7 Correct 106 ms 208 KB Output is correct
8 Correct 204 ms 208 KB Output is correct
9 Runtime error 243 ms 280 KB Execution killed with signal 13
10 Runtime error 233 ms 280 KB Execution killed with signal 13