Submission #305819


Source Code Expand

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define each(it,n) for(__typeof((n).begin()) it=(n).begin();it!=(n).end();++it)

using namespace std;

typedef long long ll;

ll f(ll x) {
    return 4LL * (x * x - x * (x - 1) / 2);  
}

void solve() {
    ll n;
    cin >> n;
    if (n == 1) {
        cout << "0 0" << endl;
        return;
    }
    n -= 2;
    
    ll low = 0, hi = 1500000000;

    while (low + 1 < hi) {
        ll mid = (low + hi) / 2;
        if (f(mid) <= n) {
            low = mid;
        } else {
            hi = mid;
        }
    }

    ll a = hi;
    n -= f(hi - 1);

    ll x = (n + 1) / 2 - a;
    ll y = (n % 2 ? -1LL : 1LL) * (a - abs(x));
    cout << x << " " << y << endl;
}

int main() {
    int q;
    cin >> q;
    rep(i, q) {
        solve();
    }
    return 0;
}

Submission Info

Submission Time
Task B - n-th Points
User y3eadgbe
Language C++ (G++ 4.6.4)
Score 100
Code Size 878 Byte
Status AC
Exec Time 593 ms
Memory 920 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 100 / 100
Status
AC × 1
AC × 11
Set Name Test Cases
Sample subtask0_sample_01.txt
All subtask0_sample_01.txt, subtask1_large_01.txt, subtask1_mini01.txt, subtask1_random01.txt, subtask1_random02.txt, subtask1_random03.txt, subtask1_random04.txt, subtask1_random05.txt, subtask1_random06.txt, subtask1_random07.txt, subtask1_random08.txt
Case Name Status Exec Time Memory
subtask0_sample_01.txt AC 23 ms 920 KB
subtask1_large_01.txt AC 481 ms 800 KB
subtask1_mini01.txt AC 386 ms 796 KB
subtask1_random01.txt AC 438 ms 792 KB
subtask1_random02.txt AC 435 ms 796 KB
subtask1_random03.txt AC 427 ms 676 KB
subtask1_random04.txt AC 555 ms 796 KB
subtask1_random05.txt AC 593 ms 672 KB
subtask1_random06.txt AC 561 ms 916 KB
subtask1_random07.txt AC 542 ms 800 KB
subtask1_random08.txt AC 533 ms 672 KB