NC222867. Double
描述
输入描述
The first line contains a positive integer , which represents the number of the characters.
The second line contains integers separated by spaces , which represents the the combat power of the character.
输出描述
The first line contains a positive integer , which represents the number of the characters who have the probability to stay till the end and become the final winner.
The second line contains integers in order separated by spaces , which represents the the index of the characters who have the probability to stay till the end and become the final winner.
示例1
输入:
3 1 2 3
输出:
2 2 3
示例2
输入:
3 2 2 4
输出:
3 1 2 3
示例3
输入:
5 1 2 30 16 1
输出:
2 3 4
C++ 解法, 执行用时: 144ms, 内存消耗: 5572K, 提交时间: 2022-05-21 14:02:06
#include<bits/stdc++.h> using namespace std; int a[500005],n,b[500005]; bool test(int x){ int k=a[x],y=x+1; x--; while((a[x]<=k||a[y]<=k)&&k<=1e9){ if(a[x]<=k) k<<=1,x--; else if(a[y]<=k) k<<=1,y++; } return k>=1e9||(!x&&y>n); } int main(){ int s=0; cin>>n,a[0]=a[n+1]=2e9+1; for(int i=1;i<=n;i++) scanf("%d",&a[i]); for(int i=1;i<=n;i++) if(test(i)) b[++s]=i; cout<<s<<endl; for(int i=1;i<=s;i++) printf("%d ",b[i]); }