Submission #1044011

# Submission time Handle Problem Language Result Execution time Memory
1044011 2024-08-05T06:22:53 Z vjudge1 Zagonetka (COI18_zagonetka) C++17
9 / 100
44 ms 416 KB
#include <bits/stdc++.h>
using namespace std;

const int N = 105;
int n, a[N], b[N], s[N];
bool edge[N][N];

bool ask(int* q){
    cout << "query ";
    for (int i = 0; i < n; i ++){
        cout << q[i] << " ";
    }
    cout << endl;

    bool res;
    cin >> res;
    return res;
}

int main(){
    cin >> n;
    for (int i = 0; i < n; i ++)
        cin >> a[i], s[i] = b[i] = a[i];

    if (n <= 6){
        for (int ii = 0; ii < n * n; ii ++){
            bool did = 0;
            for (int i = 0; i < n; i ++){
                for (int j = i + 1; j < n; j ++){
                    if (s[i] < s[j]) continue;
                    swap(s[i], s[j]);
                    if (ask(s))
                        did = 1;
                    else
                        swap(s[i], s[j]);
                }
            }

            if (!did) break;
        }

        for (int ii = 0; ii < n * n; ii ++){
            bool did = 0;
            for (int i = 0; i < n; i ++){
                for (int j = i + 1; j < n; j ++){
                    if (b[i] > b[j]) continue;
                    swap(b[i], b[j]);
                    if (ask(b))
                        did = 1;
                    else
                        swap(b[i], b[j]);
                }
            }

            if (!did) break;
        }

        cout << "end" << endl;
        for (int i = 0; i < n; i ++)
            cout << s[i] << " ";
        cout << endl;
        for (int i = 0; i < n; i ++)
            cout << b[i] << " ";
        cout << endl;
        return 0;
    }

    for (int i = 0; i < n; i ++){
        for (int j = i + 1; j < n; j ++){
            if (a[i] < a[j]){
                swap(a[i], a[j]);
                if (!ask(a))
                    edge[i][j] = 1;
                swap(a[i], a[j]);
            }
            else{
                swap(a[i], a[j]);
                if (!ask(a))
                    edge[j][i] = 1;
                swap(a[i], a[j]);
            }
        }
    }
    
    for (int i = 0; i < n; i ++){
        for (int j = i + 1; j < n; j ++){
            if (edge[i][j]){
                for (int k = 0; k < n; k ++){
                    if (i == k or j == k) continue;
                    if (a[k] < a[i] and edge[k][i]){
                        edge[i][j] = 0;
                        break;
                    }
                    if (a[k] > a[j] and edge[j][k]){
                        edge[i][j] = 0;
                        break;
                    }
                }
            }
            if (edge[j][i]){
                for (int k = 0; k < n; k ++){
                    if (i == k or j == k) continue;
                    if (a[k] < a[j] and edge[k][j]){
                        edge[i][j] = 0;
                        break;
                    }
                    if (a[k] > a[i] and edge[i][k]){
                        edge[i][j] = 0;
                        break;
                    }
                }
            }
        }
    }

    cout << "end" << endl;

    for (int i = 0; i < n; i ++){
        s[i] = i + 1;
        for (int j = 0; j < i; j ++){
            if (edge[i][j])
                s[i] = min(s[i], s[j]);
        }
        cout << i << " : " << s[i] << endl;
        for (int j = 0; j < i; j ++){
            if (s[j] >= s[i])
                s[j]++;
        }
    }

    for (int i = 0; i < n; i ++)
        cout << s[i] << " ";
    cout << endl;

    for (int i = 0; i < n; i ++){
        b[i] = n - i;
        for (int j = 0; j < i; j ++){
            if (edge[j][i])
                b[i] = max(b[i], b[j]);
        }
        for (int j = 0; j < i; j ++)
            if (b[j] <= b[i])
                b[j]--;
    }
    for (int i = 0; i < n; i ++)
        cout << b[i] << " ";
    cout << endl;

}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 344 KB Integer 0 violates the range [1, 42]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Integer 0 violates the range [1, 14]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 44 ms 416 KB Integer 0 violates the range [1, 93]
2 Halted 0 ms 0 KB -