답안 #780621

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
780621 2023-07-12T10:52:07 Z devariaota Zagrade (COI20_zagrade) C++17
0 / 100
1 ms 336 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,q;
char ans[100005];
int main(){
    cin>>n>>q;
    for (int i=1;i<=100005;i++) ans[i]=' ';
    ans[1]='('; ans[n]=')';
    ll lo=2,hi=n-1;
    while(lo<=hi){
        cout<<">>> ? "<<lo-1<<" "<<lo<<endl;
        fflush(stdout);
        ll x;
        cin>>x;
        if (x==1) {
            if (ans[lo]==' ')
                ans[lo]=')';
            if (ans[lo+1]==' ')
                ans[lo+1]='(';
            lo+=2;
        }
        else{
            if (ans[lo]==' ')
                ans[lo]='(';
            lo+=1;
        }
        cout<<">>> ? "<<hi<<" "<<hi+1<<endl;
        cin>>x;
        fflush(stdout);
        if (x==1){
            if (ans[hi]==' ')
                ans[hi]='(';
            if (ans[hi-1]==' ')
                ans[hi-1]=')';
            hi-=2;
        }
        else{
            if (ans[hi]==' ')
                ans[hi]=')';
            hi-=1;
        }
    }
    cout<<">>> ! ";
    for (int i=1;i<=n;i++){
        cout<<ans[i];
    }
}

Compilation message

zagrade.cpp: In function 'int main()':
zagrade.cpp:8:39: warning: iteration 100004 invokes undefined behavior [-Waggressive-loop-optimizations]
    8 |     for (int i=1;i<=100005;i++) ans[i]=' ';
      |                                 ~~~~~~^~~~
zagrade.cpp:8:19: note: within this loop
    8 |     for (int i=1;i<=100005;i++) ans[i]=' ';
      |                  ~^~~~~~~~
zagrade.cpp:8:39: warning: 'void* __builtin_memset(void*, int, long unsigned int)' forming offset 100005 is out of the bounds [0, 100005] of object 'ans' with type 'char [100005]' [-Warray-bounds]
    8 |     for (int i=1;i<=100005;i++) ans[i]=' ';
      |                                 ~~~~~~^~~~
zagrade.cpp:5:6: note: 'ans' declared here
    5 | char ans[100005];
      |      ^~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 336 KB Incorrect query >>>
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 336 KB Incorrect query >>>
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 336 KB Execution killed with signal 13
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 336 KB Execution killed with signal 13
2 Halted 0 ms 0 KB -