Advertisement
YEZAELP

TOI9: wizards

Jan 8th, 2021 (edited)
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.65 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. using pi = pair <int, int>;
  5. const int N = 5000005;
  6. int a[1510][2], b[1510][2], c[1510][2], d[1510][2];
  7. int n;
  8. pi hashing[N], keep[N];
  9. pi zero = {0, 0};
  10.  
  11. int main(){
  12.  
  13.     int t1, t2;
  14.     scanf("%d%d", &t1, &t2);
  15.     scanf("%d", &n);
  16.     for(int i=1;i<=n;i++) scanf("%d%d", &a[i][0], &a[i][1]);
  17.     for(int i=1;i<=n;i++) scanf("%d%d", &b[i][0], &b[i][1]);
  18.     for(int i=1;i<=n;i++) scanf("%d%d", &c[i][0], &c[i][1]);
  19.     for(int i=1;i<=n;i++) scanf("%d%d", &d[i][0], &d[i][1]);
  20.  
  21.     for(int i=1;i<=n;i++){
  22.         for(int j=1;j<=n;j++){
  23.             int hsh = abs( (3*(a[i][0] + b[j][0]) + 7*(a[i][1] + b[j][1]) + N) % N);
  24.             while(hashing[hsh] != zero){
  25.                 hsh ++;
  26.                 hsh = hsh % N;
  27.             }
  28.             hashing[hsh] = {i, j};
  29.             keep[hsh] = {a[i][0] + b[j][0], a[i][1] + b[j][1]};
  30.         }
  31.     }
  32.  
  33.     for(int i=1;i<=n;i++){
  34.         for(int j=1;j<=n;j++){
  35.             int hsh = abs( (3*(t1 - c[i][0] - d[j][0]) + 7*(t2 - c[i][1] - d[j][1]) + N) % N);
  36.             while(hashing[hsh] != zero){
  37.                 if(keep[hsh].first == t1 - c[i][0] - d[j][0] and keep[hsh].second == t2 - c[i][1] - d[j][1]){
  38.                     printf("%d %d\n", a[hashing[hsh].first][0], a[hashing[hsh].first][1]);
  39.                     printf("%d %d\n", b[hashing[hsh].second][0], b[hashing[hsh].second][1]);
  40.                     printf("%d %d\n", c[i][0], c[i][1]);
  41.                     printf("%d %d", d[j][0], d[j][1]);
  42.                     return 0;
  43.                 }
  44.                 hsh ++;
  45.                 hsh = hsh % N;
  46.             }
  47.         }
  48.     }
  49.  
  50.     return 0;
  51. }
  52.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement