結果
問題 | No.850 企業コンテスト2位 |
ユーザー | TAISA_ |
提出日時 | 2019-07-05 22:43:28 |
言語 | C++14 (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 37 ms / 2,000 ms |
コード長 | 2,392 bytes |
コンパイル時間 | 1,542 ms |
コンパイル使用メモリ | 171,512 KB |
実行使用メモリ | 24,336 KB |
平均クエリ数 | 200.11 |
最終ジャッジ日時 | 2023-09-23 17:33:46 |
合計ジャッジ時間 | 4,100 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 27 ms
23,940 KB |
testcase_01 | AC | 26 ms
24,168 KB |
testcase_02 | AC | 26 ms
23,496 KB |
testcase_03 | AC | 26 ms
24,180 KB |
testcase_04 | AC | 26 ms
24,228 KB |
testcase_05 | AC | 25 ms
23,928 KB |
testcase_06 | AC | 26 ms
24,180 KB |
testcase_07 | AC | 28 ms
23,568 KB |
testcase_08 | AC | 31 ms
23,532 KB |
testcase_09 | AC | 31 ms
24,192 KB |
testcase_10 | AC | 36 ms
24,120 KB |
testcase_11 | AC | 37 ms
23,328 KB |
testcase_12 | AC | 35 ms
23,700 KB |
testcase_13 | AC | 35 ms
23,556 KB |
testcase_14 | AC | 37 ms
23,280 KB |
testcase_15 | AC | 35 ms
23,952 KB |
testcase_16 | AC | 35 ms
23,580 KB |
testcase_17 | AC | 36 ms
23,700 KB |
testcase_18 | AC | 35 ms
23,520 KB |
testcase_19 | AC | 35 ms
23,964 KB |
testcase_20 | AC | 36 ms
23,940 KB |
testcase_21 | AC | 37 ms
23,772 KB |
testcase_22 | AC | 36 ms
23,280 KB |
testcase_23 | AC | 36 ms
23,604 KB |
testcase_24 | AC | 36 ms
23,352 KB |
testcase_25 | AC | 36 ms
24,336 KB |
testcase_26 | AC | 36 ms
23,532 KB |
testcase_27 | AC | 26 ms
23,304 KB |
ソースコード
#include <bits/stdc++.h> #define all(vec) vec.begin(), vec.end() using namespace std; using ll = long long; using P = pair<ll, ll>; constexpr ll INF = (1LL << 30) - 1LL; constexpr ll LINF = (1LL << 60) - 1LL; constexpr double eps = 1e-9; constexpr ll MOD = 1000000007LL; template <typename T> bool chmin(T& a, T b) { if(a > b) { a = b; return true; } return false; }; template <typename T> bool chmax(T& a, T b) { if(a < b) { a = b; return true; } return false; }; template <typename T> ostream& operator<<(ostream& os, vector<T> v) { for(int i = 0; i < v.size(); i++) { os << v[i] << (i + 1 == v.size() ? "\n" : " "); } return os; } template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); } template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); } template <typename T, typename V> typename enable_if<is_class<T>::value == 0>::type fill_v(T& t, const V& v) { t = v; } template <typename T, typename V> typename enable_if<is_class<T>::value != 0>::type fill_v(T& t, const V& v) { for(auto& e : t) { fill_v(e, v); } }; int ask(int x, int y) { cout << "? " << x << " " << y << endl; int s; cin >> s; return s; } int main() { cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; vector<int> v; vector<vector<int>> g(n + 10); for(int i = 1; i <= n; i++) { v.push_back(i); } while(v.size() > 1) { int m = v.size(); vector<int> v2; for(int i = 0; i < m / 2; i++) { v2.push_back(ask(v[2 * i], v[2 * i + 1])); g[v[2 * i]].push_back(v[2 * i + 1]); g[v[2 * i + 1]].push_back(v[2 * i]); } if(m % 2) { v2.push_back(v[m - 1]); } v = v2; } int t = v[0]; v.clear(); for(auto e : g[t]) { v.push_back(e); } while(v.size() > 1) { int m = v.size(); vector<int> v2; for(int i = 0; i < m / 2; i++) { v2.push_back(ask(v[2 * i], v[2 * i + 1])); g[v[2 * i]].push_back(v[2 * i + 1]); g[v[2 * i + 1]].push_back(v[2 * i]); } if(m % 2) { v2.push_back(v[m - 1]); } v = v2; } cout << "! " << v[0] << endl; }