답안 #882191

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
882191 2023-12-02T19:11:23 Z Mr_Husanboy 홀-짝 수열 (IZhO11_oddeven) C++17
0 / 100
1 ms 456 KB
#include <bits/stdc++.h>
using namespace std;



#ifdef LOCAL
#include "debugger.cpp"
#else
#define debug(...)
#endif
template<class T>
int len(T &a){
    return a.size();
}

using ll = long long;
using pii = pair<int,int>;
#define all(a) (a).begin(), (a).end()
#define ff first
#define ss second
string fileio = "";


mt19937 mt(time(nullptr));
const int mod = 1e9 + 7;
const int inf = 1e9;
const ll infl = 1e18;
const int maxn = 1e5 + 1;



void solve(){
    ll n; cin >> n;
    ll l = 0, r = 2e9;
    while(l <= r){
        ll m = (l + r) / 2;
        if((m + 1) * m / 2 <= n){
            l = m + 1;
        }else{
            r = m - 1;
        }
    }
    l --;
    debug(l);
    if(l % 2){
        ll rem = n - (l + 1) * l / 2;
        if(rem){
            cout << ((l + 1) * l / 2 - (l + 1) / 2 + rem) * 2;
        }else{
            cout << (n - (l - 1) / 2) * 2 - 1;
        }
    }else{
        ll rem = n - (l + 1) * l / 2;
        if(rem){
            cout << ((l + 1) * l / 2 - l / 2 + rem) * 2 - 1;
        }else{
            cout << (n - l / 2) * 2;
        }
    }
}

int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    auto start = chrono::high_resolution_clock::now();
    #ifndef LOCAL
    if(fileio.size()){
        freopen((fileio + ".in").c_str(), "r", stdin);
        freopen((fileio + ".out").c_str(), "w", stdout);
    }
    #endif
    int testcases = 1;
    #ifdef Tests
    cin >> testcases;
    #endif
    while(testcases --){
        solve();
        cout << '\n';
        #ifdef LOCAL
        cout << "_________________________" << endl;
        #endif
    }
    #ifdef LOCAL
    auto duration = chrono::duration_cast<chrono::microseconds>(chrono::high_resolution_clock::now() - start);
    
    cout << "time: " << (double)duration.count()/1000.0 << " milliseconds" << endl;
    #endif
    return 0;
}       

Compilation message

oddeven.cpp: In function 'int main()':
oddeven.cpp:64:10: warning: variable 'start' set but not used [-Wunused-but-set-variable]
   64 |     auto start = chrono::high_resolution_clock::now();
      |          ^~~~~
oddeven.cpp:67:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   67 |         freopen((fileio + ".in").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
oddeven.cpp:68:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   68 |         freopen((fileio + ".out").c_str(), "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 456 KB Output is correct
4 Correct 0 ms 452 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Incorrect 1 ms 348 KB Output isn't correct
14 Halted 0 ms 0 KB -