Submission #1016834

# Submission time Handle Problem Language Result Execution time Memory
1016834 2024-07-08T13:07:00 Z 8pete8 Zagrade (COI20_zagrade) C++17
100 / 100
605 ms 2012 KB
#include<iostream>
#include<stack>
#include<map>
#include<vector>
#include<string>
#include<cassert>
#include<unordered_map>
#include <queue>
#include <cstdint>
#include<cstring>
#include<limits.h>
#include<cmath>
#include<set>
#include<algorithm>
#include <iomanip>
#include<numeric>
#include<bitset>
using namespace std;
#define ll long long
#define f first
#define s second
#define pii pair<int,int>
#define ppii pair<int,pii>
#define vi vector<int>
#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define F(n) for(int i=0;i<n;i++)
#define lb lower_bound
#define ub upper_bound
#define fastio ios::sync_with_stdio(false);cin.tie(NULL);
#pragma GCC optimize ("03,unroll-lopps")
#define int long long
using namespace std;
const int mod=1e9+7,mxn=2e5+5,inf=1e18,minf=-1e18,lg=30;
//#undef int
int n,k,m,q;
void setIO(string name){
	ios_base::sync_with_stdio(0); cin.tie(0);		
	freopen((name+".in").c_str(),"r",stdin);		
	freopen((name+".out").c_str(),"w",stdout);
}
int ask(int l,int r){
    cout<<"? "<<l<<" "<<r<<endl;
    cout.flush();
    int x;cin>>x;
    return x;
}
int32_t main(){
    fastio
    cin>>n>>q;
    stack<int>st;
    vector<char>ans(n+1,'?');
    int cnt=0;
    for(int i=1;i<=n;i++){
        if(st.empty())st.push(i);
        else{
            if(ask(st.top(),i))ans[st.top()]='(',ans[i]=')',st.pop(),cnt+=2;
            else st.push(i);
        }
    }
    cnt=n-cnt;
    cnt/=2;
    for(int i=1;i<=n;i++){
        if(ans[i]=='?'){
            if(cnt)ans[i]=')',cnt--;
            else ans[i]='(';
        }
    }
    cout<<"! ";
    for(int i=1;i<=n;i++)cout<<ans[i];
}

Compilation message

zagrade.cpp:32:40: warning: bad option '-funroll-lopps' to pragma 'optimize' [-Wpragmas]
   32 | #pragma GCC optimize ("03,unroll-lopps")
      |                                        ^
zagrade.cpp:38:23: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
   38 | void setIO(string name){
      |                       ^
zagrade.cpp:43:20: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
   43 | int ask(int l,int r){
      |                    ^
zagrade.cpp:49:14: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
   49 | int32_t main(){
      |              ^
zagrade.cpp: In function 'void setIO(std::string)':
zagrade.cpp:40:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |  freopen((name+".in").c_str(),"r",stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
zagrade.cpp:41:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |  freopen((name+".out").c_str(),"w",stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 2 ms 344 KB Output is correct
3 Correct 5 ms 344 KB Output is correct
4 Correct 4 ms 344 KB Output is correct
5 Correct 4 ms 344 KB Output is correct
6 Correct 4 ms 344 KB Output is correct
7 Correct 5 ms 344 KB Output is correct
8 Correct 6 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 6 ms 344 KB Output is correct
3 Correct 5 ms 344 KB Output is correct
4 Correct 5 ms 344 KB Output is correct
5 Correct 4 ms 344 KB Output is correct
6 Correct 6 ms 344 KB Output is correct
7 Correct 3 ms 344 KB Output is correct
8 Correct 4 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 265 ms 536 KB Output is correct
3 Correct 568 ms 528 KB Output is correct
4 Correct 605 ms 528 KB Output is correct
5 Correct 577 ms 528 KB Output is correct
6 Correct 566 ms 524 KB Output is correct
7 Correct 550 ms 1404 KB Output is correct
8 Correct 596 ms 528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 568 ms 2012 KB Output is correct
3 Correct 579 ms 1604 KB Output is correct
4 Correct 574 ms 1376 KB Output is correct
5 Correct 552 ms 872 KB Output is correct
6 Correct 574 ms 1424 KB Output is correct
7 Correct 554 ms 1388 KB Output is correct
8 Correct 577 ms 528 KB Output is correct