Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_DEPRECATE
- #include <iostream>
- #include <vector>
- #include <string>
- #include <map>
- #include <set>
- #include <algorithm>
- #define li long long
- using namespace std;
- li gcd(li a, li b) {
- return b ? gcd(b, a % b) : a;
- }
- int main() {
- //freopen("input.txt", "r", stdin);
- //freopen("output.txt", "w", stdout);
- int n;
- cin >> n;
- vector<int> a(n);
- for (int i = 1; i <= n; i++) {
- a[i - 1] = i;
- }
- int k = 1, c;
- while (k) {
- k = 0;
- for (int i = 0; i < n - 1; i++) {
- cout << "? " << a[i] << ' ' << a[i + 1] << endl;
- cin >> c;
- if (c == 0) {
- swap(a[i], a[i + 1]);
- k++;
- }
- }
- }
- cout << "! " << a[0] << ' ' << a[n - 1] << endl;
- cin >> c;
- if (c == 1) {
- cout << "YES" << endl;
- for (int i = 0; i < n; i++) {
- cout << a[i] << ' ';
- }
- }
- else {
- for (int i = 1; i < n; i++) {
- cout << "? " << a[0] << ' ' << a[i] << endl;
- cin >> c;
- if (c == 0) {
- cout << "NO" << endl;
- for (int j = 0; j <= i; j++) {
- cout << a[j] << ' ';
- }
- return 0;
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement