1 条题解

  • 0
    @ 2022-8-10 16:50:11
    /*****************************************
    Note  :
    ******************************************/
    #include <queue>
    #include <math.h>
    #include <stack>
    #include <stdio.h>
    #include <iostream>
    #include <vector>
    #include <iomanip>
    #include <string.h>
    #include <algorithm>
    #define int long long
    #define IL inline
    const int N = 1e6+10;
    const int INF = 0x3f3f3f3f;
    using namespace std;
    IL int read()
    {
        char ch = getchar();
        int f = 1, num = 0;
        while(ch>'9'||ch<'0')
        {
            if(ch=='-') f = -1;
            ch=getchar();
        }
        while(ch>='0'&&ch<='9')
            num = num*10+ch-'0', ch = getchar();
        return num*f;
    }
    int n,ans[N],tot;
    struct node
    {
    	int num,id;
    };
    bool operator <(node a,node b)
    {
    	if(a.num!=b.num)
    		return a.num>b.num;
    	return a.id>b.id;
    }
    priority_queue<node> q;
    signed main()
    {
    	n=tot=read();
    	for(int i = 1;i<=n;i++)
    		q.push({read(),i});
    	while(!q.empty())
    	{
    		node x=q.top();
    		q.pop();
    		if(q.empty()) 
    		{
    			ans[x.id]=x.num;
    			break;
    		}
    		node y=q.top();
    		if(x.num==y.num)
    		{
    			q.pop(),tot--;
    			q.push({x.num*2,y.id});
    		}
    		else
    			ans[x.id]=x.num;
    	}
    	printf("%lld\n",tot);
    	for(int i = 1;i<=n;i++)
    		if(ans[i])
    			printf("%lld ",ans[i]);
    }
    
    • 1

    信息

    ID
    2351
    时间
    1000ms
    内存
    256MiB
    难度
    9
    标签
    递交数
    37
    已通过
    3
    上传者