QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#576217#9313. Make MaxbaisongRE 3ms8448kbC++141.7kb2024-09-19 19:25:522024-09-19 19:25:58

Judging History

你现在查看的是最新测评结果

  • [2024-09-19 19:25:58]
  • 评测
  • 测评结果:RE
  • 用时:3ms
  • 内存:8448kb
  • [2024-09-19 19:25:52]
  • 提交

answer

#include<iostream>
#include<vector>
#include<bits/stdc++.h>

using namespace std;
int  maxn, num;
int sz[200005], inf = 1e9 + 1;
vector<int>g[200005];

void dfs(int id, int n)
{
    for (int i = 0; i < g[id].size(); i++)
    {
        num += n;
        //cout << num << "";
        dfs(g[id][i], n + 1);
    }
}

int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        int a;
        cin >> a;
        memset(g, 0, sizeof(g));
        maxn = 0;
        for (int i = 1; i <= a; i++)
        {
            cin >> sz[i];
            maxn = max(maxn, sz[i]);
        }
        sz[0] = inf, sz[a + 1] = inf;

        for (int i = 1; i <= a; i++)
        {

            int x1 = 0;
            int x2 = 0;
            for (int j = i; j >= 1; j--)
            {
                if (sz[j] > sz[i])
                {
                    x2 = sz[j];
                    break;
                }

            }
            for (int j = i; j <= a; j++)
            {
                if (sz[j] > sz[i])
                {
                    x1 = sz[j];
                    break;
                }
            }

            int minn;
            if (x2 == 0&&x1==0)
            {
                continue;
            }
            if (x2 == 0)
            {
                minn = x1;
            }
            if (x1 == 0)
            {
                minn = x2;
            }
            if (x1 != 0 && x2 != 0)
            {
                minn=min(x1, x2);
            }
            //cout << minn<<" ";
            g[minn].push_back(sz[i]);
        }
        num = 0;
        dfs(maxn, 1);
        cout << num << endl;
    }

}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 8448kb

input:

4
2
1 2
2
2 2
7
1 1 1 2 2 2 2
3
1 2 3

output:

1
0
3
3

result:

ok 4 number(s): "1 0 3 3"

Test #2:

score: -100
Runtime Error

input:

2
198018
875421126 585870339 471894633 383529988 625397685 944061047 704695631 105113224 459022561 760848605 980735314 847376362 980571959 329939331 644635272 326439858 752879510 837384394 175179068 182094523 397239381 1199016 185143405 279638454 252374970 822030887 860312140 137248166 993229443 164...

output:


result: