Helicator

queen.cpp

Jan 5th, 2022
989
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.48 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define int long long
  5. #define vi vector<int>
  6. #define ii pair<int,int>
  7. #define fi first
  8. #define sc second
  9. #define pb push_back
  10. #define stoi stoll
  11. #define popcnt __builtin_popcount
  12. #define getbit(x, k) ((x >> k) & 1)
  13. #define all(x) (x).begin(),(x).end()
  14. #define FOR(i,j,k) for(int i=j; i<k; ++i)
  15. #define look(a) cerr <<#a<<": "<<a<<endl;
  16. #define look2(a,b) cerr <<#a<<": "<<a<<" | "<<#b<<": "<<b<< endl;
  17.  
  18. void solve()
  19. {
  20.     int n, g;
  21.     cin >> n >> g;
  22.     if (n == 0) {
  23.         // cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
  24.         exit(0);
  25.     }
  26.     int vert[n+1], hori[n+1];
  27.     int diag1[n*2], diag2[n*2];
  28.     memset(vert, 0, sizeof(vert));
  29.     memset(hori, 0, sizeof(hori));
  30.     memset(diag1, 0, sizeof(diag1));
  31.     memset(diag2, 0, sizeof(diag2));
  32.     FOR(i,0,g){
  33.         int k,x,y,s,t;
  34.         cin >> k >> x >> y >> s >> t;
  35.         FOR(j,0,k){
  36.             int a = x + j*s;
  37.             int b = y + j*t;
  38.             ++vert[a];
  39.             ++hori[b];
  40.             ++diag1[a+b-1];
  41.             ++diag2[a-b+n];
  42.         }
  43.  
  44.     }
  45.     int ans = 0;
  46.     FOR(i,1,n+1){
  47.         if (vert[i]) ans += vert[i]-1;
  48.         if (hori[i]) ans += hori[i]-1;
  49.     }
  50.     FOR(i,0,n*2){
  51.         if (diag1[i]) ans += diag1[i]-1;
  52.         if (diag2[i]) ans += diag2[i]-1;
  53.     }
  54.     cout << ans;
  55. }
  56.  
  57. signed main()
  58. {
  59.     cin.tie(0)->sync_with_stdio(0);
  60.     // freopen("in", "r", stdin);
  61.     // freopen("out", "w", stdout);
  62.     // int T = 1;
  63.     // cin >> T;
  64.     while (true) {
  65.         solve();
  66.         cout << '\n';
  67.     }
  68.     cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
  69. }
Advertisement
Add Comment
Please, Sign In to add comment