Naxocist

StudentIDs

Apr 28th, 2022
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.75 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define INF 1e9
  5.  
  6. using ll = long long;
  7. using pi = pair<int, int>;
  8. using pii = pair<pi, int>;
  9.  
  10. int a[3][10], b[3][100], c[1000];
  11.  
  12. int main(){
  13.     ios_base::sync_with_stdio(false); cin.tie(nullptr);
  14.    
  15.     int n; cin >> n;
  16.     ll cnt = 0;
  17.    
  18.     while(n--){
  19.         int s; cin >> s;
  20.  
  21.         int d = s%10, t = (s/10)%10, h = s/100; // 001 010 100
  22.         int x = s/10, y = s%100, z = (s/100)*10 + s%10;// 110 011 101
  23.  
  24.         cnt += a[0][d] + a[1][t] + a[2][h];
  25.         cnt -= b[0][x] + b[1][y] + b[2][z];
  26.         cnt += c[s]; // 111
  27.  
  28.         a[0][d]++; a[1][t]++; a[2][h]++;
  29.         b[0][x]++; b[1][y]++; b[2][z]++;
  30.         c[s]++; // 111
  31.     }
  32.     cout << cnt;
  33.     return 0;
  34.  
  35. }
  36.  
  37.  
Advertisement
Add Comment
Please, Sign In to add comment