Submission #360055

# Submission time Handle Problem Language Result Execution time Memory
360055 2021-01-27T12:28:59 Z MrRobot_28 Tenis (COCI20_tenis) C++17
80 / 110
211 ms 12856 KB
#include<bits/stdc++.h>
using namespace std;
signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    int a[3][n];
    int pos[3][n];
    vector <int> cnt(3, 0);
    vector <int> cnt1(n, 0);
    for(int i = 0; i < 3; i++)
    {
        for(int j = 0;j < n; j++)
        {
            cin >> a[i][j];
            a[i][j]--;
            pos[i][a[i][j]] = j;
        }
    }
    for(int i = 0; i < 3; i++)
    {
        int sum = 0;
        vector <int> bal(n, 0);
        vector <vector <int> > mat(n, vector <int> (8, 0));
        vector <int> mat1(8, 0);
        for(int j = n - 1; j >= 0; j--)
        {
            vector <int> vc;
            for(int t = 0; t < 3; t++)
            {
                if(a[t][j] == a[i][j])
                {
                    continue;
                }
                vc.push_back(a[t][j]);
            }
            sort(vc.begin(), vc.end());
            vc.resize(unique(vc.begin(), vc.end()) - vc.begin());
            for(int it = 0; it < vc.size(); it++)
            {
                int t = vc[it];
                bool fl = 1;
          //      cout << t << " ";
                for(int k = 0; k < 3; k++)
                {
                    if(pos[k][t] < j || pos[k][a[i][j]] < j)
                    {
                        fl = 0;
                    }
                    if(t == a[k][j])
                    {
                        if(pos[k][a[i][j]] < pos[i][t] || pos[k][a[i][j]] == pos[i][t] && k < i)
                        {
                            fl = 0;
                        }
                    }
                    else if(a[i][j] == a[k][j])
                    {
                        if(pos[k][t] < pos[i][t] || pos[k][t] == pos[i][t] && k < i)
                        {
                            fl = 0;
                        }
                    }
                }
                if(fl)
                {
                    cnt[i]++;
                    cnt1[a[i][j]]++;
                }
            }
           // cout << "\n";
            bool flag = 1;
            for(int t = 0; t < 3; t++)
            {
                if(t != i && pos[t][a[i][j]] <= j)
                {
                    flag = 0;
                }
            }
            if(flag)
            {
             //   cnt1[a[i][j]] += sum;
               // cnt[i] += sum;
            }
            int mina = j;
            for(int t =0; t < 3; t++)
            {
                mina = min(mina, pos[t][a[i][j]]);
            }
            if(mina == j)
            {
                int maskt = 0;
                for(int t = 0; t < 3; t++)
                {
                    if(t != i && a[t][j] == a[i][j])
                    {
                        maskt += (1 << t);
                    }
                }
                cnt[i] += mat1[maskt];
                cnt1[a[i][j]] += mat1[maskt];
              //  cout << mat1[maskt] << " ";
            }
            else
            {
             //   cout << 0 << " ";
            }
            int mask1 = 0;
            for(int t = 0; t < 3; t++)
            {
                if((pos[t][a[i][j]] > j || pos[t][a[i][j]] == j && t > i) && t != i)
                {
                    mask1 |= (1 << t);
                }
            }
            for(int mask2 = mask1; mask2 >= 0; mask2 = (mask2 - 1) & mask1)
            {
                mat[mina][mask2]++;
                if(mask2 == 0)
                {
                    break;
                }
            }
            for(int k = 0; k < 8; k++)
            {
                mat1[k] += mat[j][k];
            }
            bal[mina]++;
            sum += bal[j];
        }
     //   cout << "\n";
    }
    for(int i = 0; i < 3; i++)
    {
        cout << cnt[i] << " ";
    }
    cout << "\n";
    for(int i = 0; i < n; i++)
    {
        cout << cnt1[i] << " ";
    }
    return 0;
}

Compilation message

tenis.cpp: In function 'int main()':
tenis.cpp:42:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |             for(int it = 0; it < vc.size(); it++)
      |                             ~~~^~~~~~~~~~~
tenis.cpp:55:88: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   55 |                         if(pos[k][a[i][j]] < pos[i][t] || pos[k][a[i][j]] == pos[i][t] && k < i)
      |                                                           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~
tenis.cpp:62:76: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   62 |                         if(pos[k][t] < pos[i][t] || pos[k][t] == pos[i][t] && k < i)
      |                                                     ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~
tenis.cpp:114:65: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
  114 |                 if((pos[t][a[i][j]] > j || pos[t][a[i][j]] == j && t > i) && t != i)
      |                                            ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 5 ms 748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 5 ms 748 KB Output is correct
5 Correct 56 ms 5412 KB Output is correct
6 Correct 101 ms 7796 KB Output is correct
7 Correct 137 ms 10432 KB Output is correct
8 Correct 211 ms 12824 KB Output is correct
9 Partially correct 108 ms 12856 KB Partially correct
10 Partially correct 103 ms 12856 KB Partially correct