QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#567190#9313. Make MaxCuberWWA 1ms6012kbC++142.3kb2024-09-16 09:51:052024-09-16 09:51:07

Judging History

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

  • [2024-09-18 15:56:24]
  • hack成功,自动添加数据
  • (/hack/836)
  • [2024-09-16 09:51:07]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:6012kb
  • [2024-09-16 09:51:05]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
struct node
{
    int value, id;
    int size = 0;
    bool operator<(const node &x)const
    {
        return value > x.value;
    }
};
const int N = 2e5 + 10;
node a[N];
priority_queue<node> heap;
int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        int ans = 0;
        int n, idx = 0;
        scanf("%d", &n);
        vector<int> arr(n + 1, 0);
        bool flag = true;
        for (int i = 1; i <= n; i++)
        {
            scanf("%d", &arr[i]);
        }

        ++idx;
        a[idx].value = arr[1], a[idx].size = 1;

        for (int i = 2; i <= n + 1; i++)
        {
            if (arr[i] != arr[i - 1])
            {
                idx++;
                a[idx].value = arr[i], a[idx].size = 1;
            }
            else
            {
                a[idx].size++;
            }
        }
        idx--;
        if (idx == 1)
        {
        	puts("0");
        	continue;
		}
        for (int i = 1; i <= idx; i++)
        {
            a[i].id = i;
            heap.push(a[i]);
            // cout << a[i].value << " " << a[i].size << endl;
        }
        while (heap.size() > 1)
        {
            node mn = heap.top(); heap.pop();
            int i = mn.id;
            int L = i - 1, R = i + 1;
			while (a[L].size == 0 && L >= 1)
			{
				L--;
			}
			while (a[R].size == 0 && R <= n)
			{
				R++;
			}
            if (L == 0 && R <= n)
            {
                a[R].size += a[i].size;
                ans += a[i].size;
                a[i].size = 0;
            }
            else if (R == n + 1 && L >= 1)
            {
                a[L].size += a[i].size;
                ans += a[i].size;
                a[i].size = 0;
            }
            else if (L >= 1 and R <= n)
            {
            	int ttt;
            	if (a[L].value > a[R].value) ttt = R;
				else if (a[L].value < a[R].value) ttt = L;
				if (a[L].value == a[R].value)
            	{
            		ttt = R;
            		a[L].size = 0;
				}
                a[ttt].size += a[i].size;
                ans += a[i].size;
                a[i].size = 0;  
            }
        }
        cout << ans << "\n";
    }

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 6012kb

input:

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

output:

1
0
10
3

result:

wrong answer 3rd numbers differ - expected: '3', found: '10'