QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#696051 | #6695. Matching | jiangXxin | AC ✓ | 123ms | 10792kb | C++20 | 2.2kb | 2024-10-31 21:25:53 | 2024-10-31 21:25:54 |
Judging History
answer
// Problem: G. Matching
// Contest: Codeforces - The 13th Shandong ICPC Provincial Collegiate Programming Contest
// URL: https://codeforces.com/gym/104417/problem/G
// Memory Limit: 1024 MB
// Time Limit: 1000 ms
//
// Powered by CP Editor (https://cpeditor.org)
/*
/\__/\
(o o)
/ \
// ^ ^ \\
/// \\\
\ /
\____/
/\_ _/\
*/
#include<bits/stdc++.h>
#define fir first
#define sec second
#define pb push_back
#define lowbit(X) X&(-X)
#define sz(X) (int)(X).size()
#define all(X) (X).begin(),(X).end()
#define YES cout<<"YES"<<'\n'
#define Yes cout<<"Yes"<<'\n'
#define NO cout<<"NO"<<'\n'
#define No cout<<"No"<<'\n'
#define error cout<<"-1"<<'\n'
using namespace std;
typedef long long unt;
typedef long double ld;
typedef vector<int> vt_int;
typedef vector<char> vt_char;
typedef vector<bool> vt_bool;
typedef vector<long long> vt_unt;
typedef vector<long double> vt_ld;
typedef vector<vector<int> > vvt_int;
typedef vector<vector<char> > vvt_char;
typedef vector<vector<bool> > vvt_bool;
typedef vector<vector<long long> > vvt_unt;
typedef vector<vector<long double> > vvt_ld;
const long long mod=1e9+7;
const long long INF=1152921504606846976;//(2^60)
const long long N=110000;
int solve(){
unt n;
cin>>n;
vt_unt a(n+10);
unt ans=0;
vector<pair<unt,unt> >t;
for(int i=1;i<=n;i++){
cin>>a[i];
unt res=i-a[i];
t.push_back({res,a[i]});
//cout<<res<<" ";
}
//cout<<endl;
sort(all(t));
//reverse(all(t));
map<int,int>vis;
for(int i=n-1;i-1>=0;i--){
if(t[i].fir==t[i-1].fir&&!vis[i]){
// unt res=t[i].sec+t[i-1].sec;
// if(res>0){
// ans+=res;
// i--;
// continue;
// }
ans+=max(0ll,t[i].sec+t[i-1].sec);
vis[i]=vis[i-1]=true;
//i--;
}
}
cout<<ans<<endl;
return 0;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int testcase;
testcase=1;
cin>>testcase;
while(testcase--){
int flag=solve();
if(flag==1) YES;
if(flag==-1) NO;
}
return 0;
}
这程序好像有点Bug,我给组数据试试?
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3624kb
input:
3 9 3 -5 5 6 7 -1 9 1 2 3 -5 -4 -3 3 1 10 100
output:
30 0 0
result:
ok 3 number(s): "30 0 0"
Test #2:
score: 0
Accepted
time: 123ms
memory: 10792kb
input:
5504 9 -1 -7 -6 -5 -4 -3 5 -1 0 5 999999995 999999993 999999995 999999995 999999995 5 3 -6 -5 -4 -2 4 -8 2 3 -5 4 -2 -1 0 1 9 -4 -9 3 -1 -1 -5 2 -3 -5 7 -1 -2 1 2 3 4 3 4 -2 5 2 -4 10 2 4 1 -3 -2 4 5 -3 0 -4 6 -1 0 1 2 4 -3 5 -4 -3 -2 -1 0 4 -1 0 1 2 8 1 0 -4 -1 0 -5 -3 -5 2 5 6 8 -4 -3 -2 -1 0 1 2 ...
output:
4 1999999988 0 5 1 1 11 0 9 3 0 3 0 11 6 9 0 1999999989 13 1 11 7 1999999981 40 0 11 0 6 0 0 7 9 1 15 4 3 0 7 23 0 5 1999999997 0 3 5999999976 3 16 5999999943 5999999933 5 0 11 0 10 12 0 6 8 3999999982 12 0 7 0 0 3 3 0 1999999994 3999999972 1 0 16 0 0 0 7 2 0 8 0 5999999964 16 0 1 1999999995 28 0 54...
result:
ok 5504 numbers