Submission #305757
Source Code Expand
#include<cstdio>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cstring>
using namespace std;
typedef long long LL;
typedef vector<int> VI;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)
template<class T> inline void amin(T &a, const T &b) { if (a>b) a=b; }
template<class T> inline void amax(T &a, const T &b) { if (a<b) a=b; }
int main() {
int Q;
LL N;
scanf("%d", &Q);
REP ($, Q) {
scanf("%lld", &N);
N--;
if ( N == 0 ) {
puts("0 0");
continue;
}
LL lo = 0, hi = 1e9;
while (hi-lo > 1) {
LL m = (lo + hi) / 2;
if (2 * m * (m+1) + 1 > N) hi = m;
else lo = m;
}
LL Z = 2 * lo * (lo+1);
// (lo, 0) : Z
// cerr << N << " " << lo << " " << Z << '\n';
LL D = N-Z - 1;
if (D < 2 * lo + 2) {
if (D % 2 == 0) {
// /
printf("%lld %lld\n", -lo-1 + D/2, D/2);
} else {
// \ ----
printf("%lld %lld\n", -lo-1 + (D+1)/2, -(D+1)/2);
}
} else {
D = D - 2 * lo - 2;
if (D % 2 == 0) {
// \ -------
printf("%lld %lld\n", D/2, lo+1-D/2);
} else {
// /
printf("%lld %lld\n", (D+1)/2, -lo-1+(D+1)/2);
}
}
}
return 0;
}
Submission Info
Submission Time
2014-12-21 15:28:28+0900
Task
B - n-th Points
User
natsugiri
Language
C++ (G++ 4.6.4)
Score
100
Code Size
1328 Byte
Status
AC
Exec Time
156 ms
Memory
924 KB
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:22:20: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
./Main.cpp:25:19: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
Judge Result
Set Name
Sample
All
Score / Max Score
0 / 0
100 / 100
Status
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
25 ms
788 KB
subtask1_large_01.txt
AC
154 ms
672 KB
subtask1_mini01.txt
AC
98 ms
800 KB
subtask1_random01.txt
AC
133 ms
672 KB
subtask1_random02.txt
AC
136 ms
924 KB
subtask1_random03.txt
AC
134 ms
800 KB
subtask1_random04.txt
AC
154 ms
916 KB
subtask1_random05.txt
AC
156 ms
920 KB
subtask1_random06.txt
AC
155 ms
796 KB
subtask1_random07.txt
AC
152 ms
800 KB
subtask1_random08.txt
AC
153 ms
748 KB