首页 > 其他分享 >Codeforces Round #707 (Div. 1, based on Moscow Open Olympiad in Informatics) A

Codeforces Round #707 (Div. 1, based on Moscow Open Olympiad in Informatics) A

时间:2022-10-27 20:44:35浏览次数:57  
标签:based int Moscow 707 Codeforces 显然 const 我们

A. Going Home

观察ai<=2.5e6
显然我们两数之和最多5e6
我们开桶 让后怎么暴力让我发愁了
显然我们知道我们可能一个数被用了好多次 这样显然不行
可以想到就是把这个数对存下来 要是以后来的和这个都不重复才行
还有就是显然我们要是重复一个显然 另一个也是重合的
好的交上去....
居然过了???
哦 原来是我们要是n到后面显然是必定有解的
我们根据抽屉原理 显然我们每个数最多重复4次 也就是2e7的复杂度
不过为啥是4次
比如我们有四个1 3 四个1都是来自不同的下标
显然我们四个1就是解
那我们三个1 3 然后还有一个显然就是2 2
这样又是有解了
那没事了 这道题就过了

#include <bits/stdc++.h>
using namespace std;
const int N = 5e6+10;
const int M = 998244353;
const int mod = 998244353;
#define int long long
int up(int a,int b){return a<0?a/b:(a+b-1)/b;}
#define endl '\n'
#define all(x) (x).begin(),(x).end()
#define YES cout<<"YES"<<endl;
#define NO cout<<"NO"<<endl;
#define _ 0
#define pi acos(-1)
#define INF 0x3f3f3f3f3f3f3f3f
#define fast ios::sync_with_stdio(false);cin.tie(nullptr);
vector<int>v(N);
pair<int,int>q[N];
void solve(){
    int n;cin>>n;
    vector<int>a(n+10);
    for(int i=1;i<=n;i++)cin>>a[i];
    for(int i=1;i<=n;i++){
        for(int j=i+1;j<=n;j++){
            if(v[a[i]+a[j]]&&q[a[i]+a[j]].first!=i&&q[a[i]+a[j]].first!=j&&q[a[i]+a[j]].second!=i&&q[a[i]+a[j]].second!=j){
                YES
                cout<<i<<' '<<j<<' '<<q[a[i]+a[j]].first<<' '<<q[a[i]+a[j]].second<<endl;
                return;
            }else v[a[i]+a[j]]++,q[a[i]+a[j]]={i,j};
        }
    }
    NO
}
signed main(){
    fast
    int t;t=1;//cin>>t;
    while(t--) {
        solve();
    }
    return ~~(0^_^0);
}

标签:based,int,Moscow,707,Codeforces,显然,const,我们
From: https://www.cnblogs.com/ycllz/p/16833678.html

相关文章