답안 #485076

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
485076 2021-11-06T03:32:53 Z nhanbin03 Watermelon (INOI20_watermelon) C++14
0 / 100
2000 ms 1684 KB
#include <bits/stdc++.h>
#define task "INOI20_watermelon"
#define X first
#define Y second
#define left ___left
#define right ___right

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int N = 0 + 10;



int main() {
//    cin.tie(0)->sync_with_stdio(0);
//    cout.tie(0);
    if (fopen(task ".inp","r")) {
        freopen(task ".inp","r",stdin);
        freopen(task ".ans","w",stdout);
    }
    int n, k;
    cin >> n >> k;
    assert(k == 1);
    vector<int> a(n), v(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        v[i] = i;
    }
    vector<vector<int>> lst;
    do {
        vector<int> ans(n + 1);
        for (int i = 0; i < n; i++) {
            ans[v[i]] = i;
        }
        vector<int> left(n + 2), right(n + 2);
        for (int i = 0; i <= n; i++) {
            left[i + 1] = i;
            right[i] = i + 1;
        }
        vector<int> cmp(n, -1);
        int cnt = 0;
        while (++cnt) {
            bool changed = 0;
            for (int i = right[0]; i <= n; i = right[i]) {
//                cout << i << endl;
                if (ans[i - 1] < ans[right[i] - 1]) {
                    right[left[i]] = right[i];
                    left[right[i]] = left[i];
                    changed = 1;
                    cmp[i - 1] = cnt;
                }
            }
            if (changed == 0) break;
        }
        bool ok = 1;
        for (int i = 0; i < n; i++) {
            if (cmp[i] != a[i]) ok = 0;
        }
        if (ok) lst.push_back(v);
//        cout << endl;
//        for (int i = 0; i < n; i++) cout << ans[i] << " "; cout << endl;
//        for (int i = 0; i < n; i++) cout << cmp[i] << " "; cout << endl;
    } while (next_permutation(v.begin(), v.end()));
    sort(lst.begin(), lst.end());
    if (k > lst.size()) {
        cout << -1;
        return 0;
    }
    vector<int> ans(n);
    for (int i = 0; i < n; i++) {
        ans[lst[k - 1][i]] = i + 1;
    }
    for (int i = 0; i < n; i++) {
        cout << ans[i] << " ";
    }
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:69:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   69 |     if (k > lst.size()) {
      |         ~~^~~~~~~~~~~~
Main.cpp:22:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |         freopen(task ".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:23:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |         freopen(task ".ans","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 204 KB Output is correct
2 Correct 77 ms 288 KB Output is correct
3 Correct 788 ms 552 KB Output is correct
4 Correct 781 ms 204 KB Output is correct
5 Correct 792 ms 324 KB Output is correct
6 Correct 76 ms 204 KB Output is correct
7 Correct 816 ms 268 KB Output is correct
8 Correct 784 ms 204 KB Output is correct
9 Correct 77 ms 204 KB Output is correct
10 Correct 76 ms 204 KB Output is correct
11 Correct 9 ms 204 KB Output is correct
12 Runtime error 1 ms 332 KB Execution killed with signal 6
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 204 KB Output is correct
2 Correct 77 ms 288 KB Output is correct
3 Correct 788 ms 552 KB Output is correct
4 Correct 781 ms 204 KB Output is correct
5 Correct 792 ms 324 KB Output is correct
6 Correct 76 ms 204 KB Output is correct
7 Correct 816 ms 268 KB Output is correct
8 Correct 784 ms 204 KB Output is correct
9 Correct 77 ms 204 KB Output is correct
10 Correct 76 ms 204 KB Output is correct
11 Correct 9 ms 204 KB Output is correct
12 Runtime error 1 ms 332 KB Execution killed with signal 6
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2091 ms 1684 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2091 ms 1684 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 204 KB Output is correct
2 Correct 77 ms 288 KB Output is correct
3 Correct 788 ms 552 KB Output is correct
4 Correct 781 ms 204 KB Output is correct
5 Correct 792 ms 324 KB Output is correct
6 Correct 76 ms 204 KB Output is correct
7 Correct 816 ms 268 KB Output is correct
8 Correct 784 ms 204 KB Output is correct
9 Correct 77 ms 204 KB Output is correct
10 Correct 76 ms 204 KB Output is correct
11 Correct 9 ms 204 KB Output is correct
12 Runtime error 1 ms 332 KB Execution killed with signal 6
13 Halted 0 ms 0 KB -