Advertisement
anon20016

J

Nov 17th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. #define _CRT_SECURE_NO_DEPRECATE
  2.  
  3. #include <iostream>
  4. #include <vector>
  5. #include <string>
  6. #include <map>
  7. #include <set>
  8. #include <algorithm>
  9.  
  10. #define li long long
  11.  
  12. using namespace std;
  13.  
  14. li gcd(li a, li b) {
  15. return b ? gcd(b, a % b) : a;
  16. }
  17.  
  18.  
  19. int main() {
  20. //freopen("input.txt", "r", stdin);
  21. //freopen("output.txt", "w", stdout);
  22.  
  23. int n;
  24. cin >> n;
  25. vector<int> a(n);
  26. for (int i = 1; i <= n; i++) {
  27. a[i - 1] = i;
  28. }
  29.  
  30. int k = 1, c;
  31. while (k) {
  32. k = 0;
  33. for (int i = 0; i < n - 1; i++) {
  34. cout << "? " << a[i] << ' ' << a[i + 1] << endl;
  35. cin >> c;
  36. if (c == 0) {
  37. swap(a[i], a[i + 1]);
  38. k++;
  39. }
  40. }
  41. }
  42. cout << "! " << a[0] << ' ' << a[n - 1] << endl;
  43. cin >> c;
  44. if (c == 1) {
  45. cout << "YES" << endl;
  46. for (int i = 0; i < n; i++) {
  47. cout << a[i] << ' ';
  48. }
  49. }
  50. else {
  51. for (int i = 1; i < n; i++) {
  52. cout << "? " << a[0] << ' ' << a[i] << endl;
  53. cin >> c;
  54. if (c == 0) {
  55. cout << "NO" << endl;
  56. for (int j = 0; j <= i; j++) {
  57. cout << a[j] << ' ';
  58. }
  59. return 0;
  60. }
  61. }
  62. }
  63. return 0;
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement