結果
問題 |
No.253 ロウソクの長さ
|
ユーザー |
![]() |
提出日時 | 2024-10-12 12:59:44 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 457 bytes |
コンパイル時間 | 1,905 ms |
コンパイル使用メモリ | 191,228 KB |
最終ジャッジ日時 | 2025-02-24 17:29:12 |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | WA * 36 |
コンパイルメッセージ
main.cpp: In function ‘int ask(int)’: main.cpp:7:16: warning: ‘res’ is used uninitialized [-Wuninitialized] 7 | return res; | ^~~ main.cpp:6:13: note: ‘res’ was declared here 6 | int res; | ^~~
ソースコード
#include <bits/stdc++.h> using namespace std; int ask(int y){ cout<<"? "<<y<<endl; int res; return res; } int solve(int l,int r){ if(l-r==1)return l; if(l==0){ int a=ask(1); if(a==-1)return 0; else if(a==0)return 1; else return 1+solve(1,r-1); }else{ int mid=l+(r-l)/2; int a=ask(mid); if(a==0)return mid; else if(a==-1)return 1+solve(l-1,mid-1); else return 1+solve(mid,r-1); } } int main(){ cout<<"! "<<solve(0,1e9+1)<<endl; }