1815B - Sum Graph - CodeForces Solution


brute force constructive algorithms graphs implementation interactive shortest paths trees *2000

Please click on ads to support us..

C++ Code:

#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int tc;
    cin>>tc;
    while(tc--){
        int n,i,j,k,l;
         cin>>n;
        l=1;
        cout<<"+ "<<n+1<<endl;
        cin>>k;
        cout<<"+ "<<n<<endl;
        cin>>k;
       
        vector<int>v;
        long long r=n;
        while(l<=r){
            if(l==r){
                v.push_back(l);l++;
            }
            else{
                v.push_back(r);r--;
                v.push_back(l);l++;
            }
        }
        int mx=-1,mx_ind=-1,ans1[n+2],ans2[n+2],p;
        for(i=2;i<=n;i++){
            cout<<"? "<<1<<" "<<i<<endl;
            cin>>p;
            if(p>mx){
                mx=p;
                mx_ind=i;
            }
        }
        for(i=1;i<=n;i++){
            if(i==mx_ind){
                ans1[i]=v[0];
                ans2[i]=v[n-1];
            }
            else{
                cout<<"? "<<mx_ind<<" "<<i<<endl;
                cin>>p;
                ans1[i]=v[p];
                ans2[i]=v[n-p-1];
            }
        }
        cout<<"! ";
        for(i=1;i<=n;i++)cout<<ans1[i]<<" ";
        for(i=1;i<=n;i++)cout<<ans2[i]<<" ";
        cout<<endl;cin>>k;

    }
}


Comments

Submit
0 Comments
More Questions

1666L - Labyrinth
1294B - Collecting Packages
1642B - Power Walking
1424M - Ancient Language
600C - Make Palindrome
1669D - Colorful Stamp
1669B - Triple
1669A - Division
1669H - Maximal AND
1669E - 2-Letter Strings
483A - Counterexample
3C - Tic-tac-toe
1669F - Eating Candies
1323B - Count Subrectangles
991C - Candies
1463A - Dungeon
1671D - Insert a Progression
1671A - String Building
1671B - Consecutive Points Segment
1671C - Dolce Vita
1669G - Fall Down
4D - Mysterious Present
1316B - String Modification
1204A - BowWow and the Timetable
508B - Anton and currency you all know
1672A - Log Chopping
300A - Array
48D - Permutations
677C - Vanya and Label
1583B - Omkar and Heavenly Tree