제출 #1051672

#제출 시각아이디문제언어결과실행 시간메모리
1051672otariusColors (BOI20_colors)C++17
100 / 100
2 ms700 KiB
#include <bits/stdc++.h>
#include <bits/extc++.h>
using namespace __gnu_pbds;
using namespace std;

// #pragma GCC optimize("Ofast")
// #pragma GCC optimize ("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define ff first
#define sc second
#define pb push_back
#define ll long long
#define pll pair<ll, ll>
#define pii pair<int, int>
#define ull unsigned long long
#define all(x) (x).begin(),(x).end()

// #define int long long
// #define int unsigned long long

// #define ordered_set(T) tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>
// #define ordered_multiset(T) tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>

void open_file(string filename) {
    freopen((filename + ".in").c_str(), "r", stdin);
    freopen((filename + ".out").c_str(), "w", stdout);
}

// const ll mod = 1e9 + 7;
// const ll mod = 998244353;

const ll inf = 1e9;
const ll biginf = 1e18;
const int maxN = 1e5 + 25;

int ask(ll m) {
    cout << "? " << m << endl;
    int x; cin >> x; return x;
}
void solve() {
    ll n, x;
    cin >> n;
    vector<ll> v;
    ll l = 0, r = n, pos = 1;
    while (r - l > 1) {
        v.pb((l + r) / 2);
        l = (l + r) / 2;
    } for (int i = v.size() - 1; i >= 0; i--) {
        if (pos + v[i] <= n) pos += v[i];
        else pos -= v[i];
    } ask(pos);
    set<ll> used;
    used.insert(pos);
    l = 0; r = n;
    while (r - l > 1) {
        ll m = (l + r) / 2;
        if (pos + m <= n && used.find(pos + m) == used.end()) pos += m;
        else pos -= m;
        x = ask(pos);
        used.insert(pos);
        if (x) r = m;
        else l = m;
    } cout << "= " << r << endl;
}
int32_t main() { 
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    
    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
        cout << '\n';
    }
    return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

Colors.cpp: In function 'void open_file(std::string)':
Colors.cpp:26:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |     freopen((filename + ".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Colors.cpp:27:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |     freopen((filename + ".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...