結果

問題 No.3591 I Love Graph
コンテスト
ユーザー yuunegi
提出日時 2026-07-17 22:40:54
言語 C++23
(gcc 15.2.0 + boost 1.90.0)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
RE  
実行時間 -
コード長 1,799 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,169 ms
コンパイル使用メモリ 341,464 KB
実行使用メモリ 5,888 KB
平均クエリ数 2908.94
最終ジャッジ日時 2026-07-17 22:41:03
合計ジャッジ時間 6,217 ms
ジャッジサーバーID
(参考情報)
judge1_1 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 28 RE * 8
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    cin>>n;
    stack<array<int,5>>st;
    vector<array<int,2>>ans;
    for(int i=0;i<n-1;i+=2){
        st.push({i,i,i+1,i+1,0});
        if(i+2<=n-1)st.push({i,i+1,i+2,n-1,0});
    }
    int q=0;
    while(!st.empty()){
        array<int,5>tmp=st.top();
        st.pop();
        if(q>4500)return 1;
        q++;
        cout<<"? "<<tmp[1]-tmp[0]+1<<" "<<tmp[3]-tmp[2]+1<<" ";
        for(int i=tmp[0];i<=tmp[1];i++){
            cout<<i+1<<" ";
        }
        for(int i=tmp[2];i<=tmp[3];i++){
            cout<<i+1<<(i!=tmp[3]?" ":"");
        }
        cout<<endl;
        int a;
        cin>>a;
        if(a==-1)return 1;
        if(a){
            if(tmp[0]==tmp[1]&&tmp[2]==tmp[3]){
                ans.push_back({tmp[0],tmp[2]});
            }else if(tmp[2]==tmp[3]){
                st.push({tmp[0],tmp[0],tmp[2],tmp[2],0});
                st.push({tmp[1],tmp[1],tmp[2],tmp[2],1});
            }else{
                st.push({tmp[0],tmp[1],tmp[2],(tmp[2]+tmp[3])/2,0});
                st.push({tmp[0],tmp[1],(tmp[2]+tmp[3])/2+1,tmp[3],1});
            }
        }else if(tmp[4]==1){
            tmp=st.top();
            st.pop();
            if(tmp[0]==tmp[1]&&tmp[2]==tmp[3]){
                ans.push_back({tmp[0],tmp[2]});
            }else if(tmp[2]==tmp[3]){
                st.push({tmp[0],tmp[0],tmp[2],tmp[2],0});
                st.push({tmp[1],tmp[1],tmp[2],tmp[2],1});
            }else{
                st.push({tmp[0],tmp[1],tmp[2],(tmp[2]+tmp[3])/2,0});
                st.push({tmp[0],tmp[1],(tmp[2]+tmp[3])/2+1,tmp[3],1});
            }
        }
    }
    cout<<"! "<<ans.size()<<endl;
    for(int i=0;i<ans.size();i++){
        cout<<ans[i][0]+1<<" "<<ans[i][1]+1<<endl;
    }
    return 0;
}
0