QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#573892#9313. Make MaxChief_NingTL 1ms3616kbC++142.1kb2024-09-18 20:13:142024-09-18 20:13:15

Judging History

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

  • [2024-09-18 20:13:15]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:3616kb
  • [2024-09-18 20:13:14]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define endl "\n"
#define pq priority_queue<int>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define debug1(x) cout<<x<<endl;
#define debug2(a,b) cout<<a<<" "<<b<<endl;
const int INF = 0x3f3f3f3f;//无穷大
const int inf = 0xc0c0c0c0;//无穷小
const int MOD = 1;
const int N = 1;

/*
 ________  ___  ___  ___  _______   ________ ________   ___  ________   ________
|\   ____\|\  \|\  \|\  \|\  ___ \ |\  _____\\   ___  \|\  \|\   ___  \|\   ____\
\ \  \___|\ \  \\\  \ \  \ \   __/|\ \  \__/\ \  \\ \  \ \  \ \  \\ \  \ \  \___|
 \ \  \    \ \   __  \ \  \ \  \_|/_\ \   __\\ \  \\ \  \ \  \ \  \\ \  \ \  \  ___
  \ \  \____\ \  \ \  \ \  \ \  \_|\ \ \  \_| \ \  \\ \  \ \  \ \  \\ \  \ \  \|\  \
   \ \_______\ \__\ \__\ \__\ \_______\ \__\   \ \__\\ \__\ \__\ \__\\ \__\ \_______\
    \|_______|\|__|\|__|\|__|\|_______|\|__|    \|__| \|__|\|__|\|__| \|__|\|_______|
                                                                                     */


void ChiefNing()
{
    int n;
    cin>>n;
    vector<int> v(n);
    set<int> s;
    map<int,int> mp;
    int maxx=0;
    for(int i=0;i<n;i++){
        cin>>v[i];
        mp[v[i]]++;
        s.insert(v[i]);
        maxx=max(maxx,v[i]);
    }
    int ans=0;
    for(auto t:s){
        while(mp[t]){
            for(int i=0;i<n;i++){
                if(mp[maxx]==n){
                    cout<<ans<<endl;
                    return ;
                }
                if(v[i]==t){
                    int l=i-1,r=i+1;
                    int minn=0;
                    if(l>=0)minn=max(minn,v[l]);
                    if(r<n)minn=max(minn,v[r]);
                    if(minn==t)continue;
                    mp[v[i]]--;
                    v[i]=minn;
                    mp[minn]++;
                    ans++;
                }
            }
        }
    }
}


signed main(void)
{
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int _;
    cin>>_;
    while(_--)
        ChiefNing();
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3616kb

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
Time Limit Exceeded

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: