pdpd123

Problem 17

Feb 17th, 2020
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.88 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <cstring>
  4. using namespace std;
  5.  
  6. const int MAX_N = 5002;
  7. int v[MAX_N];
  8. int z[MAX_N]; //number of time
  9. int ans[MAX_N];
  10.  
  11. int main () {
  12.     int n;
  13.     while (scanf("%d",&n) != EOF) {
  14.         memset(ans,0,sizeof(ans));
  15.         for (int x=1;n>=x;x++) scanf("%d",&v[x]);
  16.         for (int x=1;n>=x;x++) {
  17.             memset(z,0,sizeof(z));
  18.             int num=1;
  19.             int id=v[x];
  20.             ans[id]++;
  21.             z[id]=1;
  22.             for (int j=x+1;n>=j;j++) {
  23.                 z[v[j]]++;
  24.                 if (v[j] == id) {
  25.                     ans[id]++;
  26.                     num++;
  27.                 }
  28.                 else {
  29.                     if (z[v[j]]>num) {
  30.                         num=z[v[j]];
  31.                         id = v[j];
  32.                         ans[id]++;
  33.                     }
  34.                     else if (z[v[j]] == num && v[j]<id) {
  35.                         num=z[v[j]];
  36.                         id = v[j];
  37.                         ans[id]++;
  38.                     }
  39.                     else {
  40.                         ans[id]++;
  41.                     }
  42.                 }
  43.             }
  44.         }
  45.         for (int x=1;n>=x;x++) {
  46.             if (x!=1) printf(" ");
  47.             printf("%d",ans[x]);
  48.         }
  49.         puts("");
  50.     }
  51. }
Add Comment
Please, Sign In to add comment