QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#181073#6695. MatchingiamshiqingCompile Error//C++141.6kb2023-09-16 15:34:542023-09-16 15:34:54

Judging History

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

  • [2023-09-16 15:34:54]
  • 评测
  • [2023-09-16 15:34:54]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
const int N = 1e5 + 10;
const int P = 1e9 + 7;
int a[N];
map<int, int>mp;

void solve() {
	int pos = 1;
	priority_queue<int>ans[N];
	mp.clear();
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) cin >> a[i];
	for (int i = 1; i <= n; i++) {
		int tmp = i - a[i];
		if (mp.find(tmp) != mp.end()) {
			ans[mp[tmp]].push(a[i]);
		} else {
			mp[tmp] = pos++;
			ans[mp[tmp]].push(a[i]);
		}
	}
	int res = 0;
	for (int i = 1; i < pos; i++) {
		while(ans[i].size()>=2){
			int tmp=ans[i].top();
			ans[i].pop();
			tmp+=ans[i].top();
			ans[i].pop();
			if(tmp>0) res+=tmp;
		}
	}
	cout<<res<<endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int _ = 1;
	cin>>_;
	while (_--) {
		solve();
	}
	return 0;
}#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define P pair<int,int>
#define f first 
#define s second
using namespace std;
void solve(){
    int n;
    cin>>n;
    int a[n];
    vector<P>b;
    for(int i=0;i<n;i++){
        cin>>a[i];
        b.push_back({i-a[i],i});
    }
    sort(b.begin(),b.end(),greater<P>());
    map<int,int>mp;
    int ans=0;
    for(int i=0;i+1<n;i++){
        if(b[i].f==b[i+1].f&&mp[b[i].s]==0&&mp[b[i+1].s]==0&&b[i].s-b[i].f+b[i+1].s-b[i+1].f>=0){
            ans+=b[i].s-b[i].f+b[i+1].s-b[i+1].f;
            mp[b[i].s]=1;
            mp[b[i+1].s]=1;
        }
    }
    cout<<ans<<endl;
    return;
}


signed main(){
    int _=1;
    cin>>_;
    while(_--){
        solve();
    }
}

Details

answer.code:49:2: error: stray ‘#’ in program
   49 | }#include<bits/stdc++.h>
      |  ^
answer.code:49:3: error: ‘include’ does not name a type
   49 | }#include<bits/stdc++.h>
      |   ^~~~~~~
answer.code:56:6: error: redefinition of ‘void solve()’
   56 | void solve(){
      |      ^~~~~
answer.code:10:6: note: ‘void solve()’ previously defined here
   10 | void solve() {
      |      ^~~~~
answer.code:80:8: error: redefinition of ‘int main()’
   80 | signed main(){
      |        ^~~~
answer.code:39:8: note: ‘int main()’ previously defined here
   39 | signed main() {
      |        ^~~~