제출 #1350463

#제출 시각아이디문제언어결과실행 시간메모리
1350463FIFI_cppStaring Contest (BOI23_staringcontest)C++20
100 / 100
3 ms460 KiB
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <deque>
#include <fstream>
#include <iterator>
#include <set>
#include <map>
#include <unordered_map>
#include <iomanip>
#include <cctype>
#include <string>
#include <cassert>
#include <set>
#include <bitset>
#include <unordered_set>
#include <numeric>

#define all(a) a.begin(), a.end()
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define ppi pair<int,pair<int,int>>
#define int int64_t

using namespace std;
//    /\_/\
//   (= ._.)
//   / >  \>
// encouraging cat
const int INF = 10000000000000000;
//const int mod = 1000000007;
const int mod = 998244353;
const int MAXN = 200005;
//ifstream fin('xor.in');
//ofstream fout('xor.out');
int ask(int i, int j)
{
    cout << "? " << i << " " << j << '\n';
    cout.flush();
    int x;
    cin >> x;
    return x;
}
signed main()
{
    int n;
    cin >> n;
    vector<int> res(n + 1, 0);
    vector<int> values(n, 0);
    for (int i = 0;i < n;i++)
    {
        values[i] = i + 1;
    }
    random_device rd;
    mt19937 g(rd());   // Seed once
    shuffle(all(values), g);
    values.insert(values.begin(), 0);
    int p1 = values[1], p2 = values[2];
    int v = ask(p1, p2);
    for (int i = 3;i <= n;i++)
    {
        int va = ask(values[i], p1);
        if (va < v)
        {
            res[values[i]] = va;
            continue;
        }
        int vb = ask(values[i], p2);
        if (va == v)
        {
            res[p1] = v;
            p1 = values[i];
            v = vb;
        }
        else if (vb == v)
        {
            res[p2] = v;
            p2 = values[i];
            v = va;
        }
    }
    res[p1] = v;
    res[p2] = v;
    cout << "! ";
    for (int i = 1;i <= n;i++)
    {
        cout << res[i] << " ";
    }
    cout << '\n';
    cout.flush();
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...