Submission #202865

# Submission time Handle Problem Language Result Execution time Memory
202865 2020-02-18T12:09:59 Z rdd6584 Sob (COCI19_sob) C++14
39 / 110
51 ms 4984 KB
#include <bits/stdc++.h>
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
using namespace std;

typedef long long ll;
typedef unsigned long long llu;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<string, int> psi;
typedef pair<char, int> pci;
typedef pair<int, char> pic;
const ll MOD = (ll)1e9 + 7;
const long double PI = 3.141592653589793238462643383279502884197;

priority_queue<int, vector<int>, greater<int>> pq;
int ans[500001];

void solve(int n, int m) {
    if (n == 1) ans[0] = m;
    if (n <= 1) return;

    int t = -1;
    for (int i = 1; i < 21; i++) {
        int a = (1 << i) - 1;
        if (a < n) t = a;
    }

    int k = -1;
    for (int i = m; i < m + n; i++) {
        if ((t & i) == t) {
            k = i;
            break;
        }
    }

    // t와 k의 싱크가 일치.
    // t~n과 k~k+(n-t)의 짝을 지어줌.
    // 0~1, 3~4니까.
    // 1이 3이랑 매칭되고.
    //

    for (int i = t; i < n; i++) ans[i] = k + (i - t);
    for (int i = k - 1; i >= m; i--) ans[t - (k - i)] = i;
    solve(t - (k - m), k + (n - t));
}

int main() {
    int n, m;
    scanf("%d %d", &n, &m);
    solve(n, m);

    for (int i = 0; i < n; i++)
        printf("%d %d\n" , i, ans[i]);
}

Compilation message

sob.cpp: In function 'int main()':
sob.cpp:53:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &n, &m);
     ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 248 KB Output is correct
2 Correct 6 ms 256 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 51 ms 4984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 51 ms 4856 KB Output is correct
7 Correct 31 ms 2552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Incorrect 5 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 248 KB Output is correct
2 Correct 6 ms 256 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 51 ms 4984 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 256 KB Output is correct
8 Correct 5 ms 256 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 51 ms 4856 KB Output is correct
11 Correct 31 ms 2552 KB Output is correct
12 Correct 5 ms 256 KB Output is correct
13 Incorrect 5 ms 376 KB Output isn't correct
14 Halted 0 ms 0 KB -