답안 #24180

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
24180 2017-06-01T09:51:01 Z chpipis Nizovi (COI14_nizovi) C++11
100 / 100
73 ms 2024 KB
#include <bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pf push_front
#define iter(v, i) for (__typeof__((v).begin()) i = (v).begin(); i != (v).end(); i++)
#define fast_io_without_cstdio ios_base::sync_with_stdio(false), cin.tie(NULL)
#define all(v) (v).begin(), (v).end()
#define rep(i, s, e) for (int i = s; i < e; i++)

#ifdef __linux__
#define gc getchar_unlocked
#define pc putchar_unlocked
#else
#define gc getchar
#define pc putchar
#endif

#if __cplusplus <= 199711L
template<class BidirIt>
BidirIt prev(BidirIt it, typename iterator_traits<BidirIt>::difference_type n = 1) {
    advance(it, -n);
    return it;
}

template<class ForwardIt>
ForwardIt next(ForwardIt it, typename iterator_traits<ForwardIt>::difference_type n = 1) {
    advance(it, n);
    return it;
}
#endif

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long double ldouble;

const double EPS = 1e-9;
const double PI = 3.141592653589793238462;

template<typename T>
inline T sq(T a) { return a * a; }

//#ifdef LOCAL_MACHINE
//#endif

ll ops = 0, cost = 0;

int comp(int i, int j) {
    if (i == j) return 0;
    ops++;
    assert(ops <= ( ll )1e5);
    printf("cmp %d %d\n", i, j);
    fflush(stdout);
    int res;
    scanf("%d", &res);
    return res;
}

void rev(int i, int j) {
    if (i >= j) return;
    cost += j - i + 1;
    ops++;
    assert(cost <= ( ll )3e6);
    assert(ops <= ( ll )1e5);
    printf("reverse %d %d\n", i, j);
    fflush(stdout);
}

int aft[1005];

int main() {
    //freopen("", "r", stdin);
    //freopen("", "w", stdout);
    int len_a, len_b;
    scanf("%d %d", &len_a, &len_b);
    for (int a = 1; a <= len_a; a++) {
        int lo = len_a, hi = len_a + len_b;
        while (lo < hi) {
            int mid = (lo + hi + 1) >> 1;
            if (comp(a, mid) <= 0)
                hi = mid - 1;
            else
                lo = mid;
        }
        aft[a] = lo;
    }
    int cnt = 0;
    for (int i = 1; i <= len_a; i++) {
        if (aft[i] == aft[i - 1]) continue;
        if (aft[i] == len_a) continue;
        int a = i + cnt;
        //cerr << "wanting to place " << a << " after " << aft[i] << endl;
        int cur = (aft[i] - a + 1) - (len_a - i + 1);
        rev(a, aft[i]);
        rev(a, a + cur - 1);
        rev(a + cur, aft[i]);
        cnt += cur;
    }
    puts("end");
    fflush(stdout);
    return 0;
}

Compilation message

nizovi.cpp: In function 'int comp(int, int)':
nizovi.cpp:61:22: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &res);
                      ^
nizovi.cpp: In function 'int main()':
nizovi.cpp:81:35: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &len_a, &len_b);
                                   ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2024 KB Output is correct
2 Correct 3 ms 2024 KB Output is correct
3 Correct 0 ms 2024 KB Output is correct
4 Correct 16 ms 2024 KB Output is correct
5 Correct 19 ms 2024 KB Output is correct
6 Correct 9 ms 2024 KB Output is correct
7 Correct 26 ms 2024 KB Output is correct
8 Correct 73 ms 2024 KB Output is correct
9 Correct 59 ms 2024 KB Output is correct
10 Correct 43 ms 2024 KB Output is correct