Submission #640233

# Submission time Handle Problem Language Result Execution time Memory
640233 2022-09-14T03:58:54 Z kebine Zagrade (COI20_zagrade) C++17
0 / 100
733 ms 4244 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define db double
#define pairll pair<ll,ll>
#define lpairll pair<ll,pairll>

#define repp(i,a,b) for (ll i = a; i <= b; i++)
#define repz(i,a,b) for (ll i = a; i < b; i++)
#define repm(i,a,b) for (ll i = a; i >= b; i--)
#define fr first
#define sc second
#define mp make_pair
#define pb push_back

const ll N = 5e5+5, MOD = 1e9+7, M = 1e3+5;
ll tc = 1, n, m, ar[N], br[N], str[M][M];
ll x, y, k, open = 0, close = 0;
string s, s1, s2, ye = "YES", no = "NO";
vector<pairll> v;

ll ask(ll l, ll r){
  if(ar[l] != -1 && ar[r] != -1 && (r-l) == 1){
    if (ar[l] == 0 && ar[r] == 1) return 1;
    return 0;
  }
  cout << "? " << l << " " << r << endl;
  ll dum; cin >> dum;
  return dum;
}

void input(){
  cin >> n >> k;
}

void answ(){
  cout << "! ";
  repp(i,1,n){
    if (ar[i] == 0) cout << "(";
    else cout << ")";
  }
  cout << endl;
}

void sub12(){
  memset(str,-1,sizeof(str));
  repp(i,1,n){
    repp(j,i+1,n){
      if ((j-i)%2) ask(i,j);
    }
  }

}

void sub3(){
  ll l = 1, r = n;
  memset(ar,-1,sizeof(ar));
  while(l < r){
    ll a1 = ask(l,r);
    if (a1 == 1){
      ar[l] = 0;
      ar[r] = 1;
      l++;
      r--;
      continue;
    }
    else{
      ll a2 = ask(l-1,l);
      if (a2 == 1){
        ar[l] = 1;
      }
      else ar[l] = 0;
      ll a3 = ask(r,r+1);
      if (a3 == 1){
        ar[r] = 0;
      }
      else ar[r] = 0;
      if (ar[l] && ar[r] == 0){
        l++;
        r--;
        if (l < r){
          ar[l] = 0;
          ar[r] = 1;
          l++;
          r--;
          continue;
        }
      }
      else if (ar[l] && ar[r]){
        l++;
        ar[l] = 0;
        l++;
      }
      else{
        r--;
        ar[r] = 1;
        r--;
      }
    }
  }
  answ();
}

void build(){
  memset(ar,-1,sizeof(ar));
  repp(i,1,n-1){
    br[i] = ask(i,i+1);
    if (br[i] == 1){
      ar[i] = 0;
      ar[i+1] = 1;
      open++; close++;
    }
  }
  if (ar[0] == -1){
    ar[0] = 0;
    open++;
  }
  if (ar[n] == -1){
    ar[n] = 1;
    close++;
  }
  repp(i,2,n){
    if (ar[i] != -1) break;
    ar[i] = 0;
    open++;
    if (open >= n/2) break;
  }
  repm(i,n-1,1){
    if (ar[i] != -1) break;
    ar[i] = 1;
    close++;
    if (close >= n/2) break;
  }
  
  ll l = -1, r = -1;
  repp(i,1,n){
    if (ar[i] == -1){
      if (l == -1){
        l = i;
      }
      r = i;
    }
    else{
      if (l != -1){
        v.pb(mp(l,r));
        l = r = -1;
      }
    }
  }
}

void solve(){
  sub3();
  //answ();
}

int main(){
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  //cin >> tc;
  while(tc--){
    input();
    solve();
  }
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4176 KB Output is correct
2 Correct 8 ms 4176 KB Output is correct
3 Incorrect 11 ms 4176 KB Mismatch at position 13. Expected (, found )
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 4244 KB Execution killed with signal 13
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4176 KB Output is correct
2 Correct 489 ms 4228 KB Output is correct
3 Incorrect 733 ms 4220 KB Mismatch at position 20. Expected (, found )
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 4176 KB Execution killed with signal 13
2 Halted 0 ms 0 KB -