#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
typedef long long ll;
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
bool good(int a, int b, pair<int, int> x) {
auto[c,d] = x;
if(c==d || c==a || c==b || d==a || d==b) return 0;
return 1;
}
int gn(int a, int b) {
return a + rand() % (b - a + 1);
}
int main() {
srand(67);
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n = 1000;
vector<vector<pair<int, int>>> F(n, vector<pair<int, int>>(n));
vector<vector<pair<int, int>>> G(n, vector<pair<int, int>>(n));
for(int i=0; i<n; ++i) for(int j=0; j<n; ++j) if(i!=j) F[i][j] = {i,j};
int ile = 0;
for(int i=0; i<n; ++i) for(int j=0; j<n; ++j) {
if(i==j) continue;
if(!good(i,j,F[i][j])) {
bool found = 0;
while(!found) {
int x = gn(0,n-1);
int y = gn(0,n-1);
if(x!=y && good(i,j,F[x][y]) && good(x,y,F[i][j])) {
found = 1;
swap(F[i][j], F[x][y]);
}
// ile++;
}
}
}
// cout << ile << "\n";
for(int i=0; i<n; ++i) for(int j=0; j<n; ++j) {
if(i==j) continue;
auto[a,b] = F[i][j];
G[a][b] = {i,j};
}
/*for(int i=0; i<n; ++i) for(int j=0; j<n; ++j) {
if(i==j) continue;
if(!good(i,j,F[i][j])) {
cout << "ANS - " << i << " " << j << "\n";
return 0;
}
}
cout << "OK\n";*/
string s; cin >> s;
if(s=="Algosia") {
int a, b;
cin >> a >> b;
--a; --b;
auto[c,d] = F[a][b];
cout << c+1 << " " << d+1 << "\n";
} else {
int a, b;
cin >> a >> b;
--a; --b;
auto[c,d] = G[a][b];
cout << c+1 << " " << d+1 << "\n";
}
return 0;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> typedef long long ll; using namespace __gnu_pbds; using namespace std; template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; bool good(int a, int b, pair<int, int> x) { auto[c,d] = x; if(c==d || c==a || c==b || d==a || d==b) return 0; return 1; } int gn(int a, int b) { return a + rand() % (b - a + 1); } int main() { srand(67); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n = 1000; vector<vector<pair<int, int>>> F(n, vector<pair<int, int>>(n)); vector<vector<pair<int, int>>> G(n, vector<pair<int, int>>(n)); for(int i=0; i<n; ++i) for(int j=0; j<n; ++j) if(i!=j) F[i][j] = {i,j}; int ile = 0; for(int i=0; i<n; ++i) for(int j=0; j<n; ++j) { if(i==j) continue; if(!good(i,j,F[i][j])) { bool found = 0; while(!found) { int x = gn(0,n-1); int y = gn(0,n-1); if(x!=y && good(i,j,F[x][y]) && good(x,y,F[i][j])) { found = 1; swap(F[i][j], F[x][y]); } // ile++; } } } // cout << ile << "\n"; for(int i=0; i<n; ++i) for(int j=0; j<n; ++j) { if(i==j) continue; auto[a,b] = F[i][j]; G[a][b] = {i,j}; } /*for(int i=0; i<n; ++i) for(int j=0; j<n; ++j) { if(i==j) continue; if(!good(i,j,F[i][j])) { cout << "ANS - " << i << " " << j << "\n"; return 0; } } cout << "OK\n";*/ string s; cin >> s; if(s=="Algosia") { int a, b; cin >> a >> b; --a; --b; auto[c,d] = F[a][b]; cout << c+1 << " " << d+1 << "\n"; } else { int a, b; cin >> a >> b; --a; --b; auto[c,d] = G[a][b]; cout << c+1 << " " << d+1 << "\n"; } return 0; } |
English