code festival 2014 上海

Submission #695078

Source codeソースコード

#include<cmath>
#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)
#define eprintf(s...) fprintf(stderr, s)
 
template<class T> inline void amin(T &a, const T &b) { if (b<a) a=b; }
template<class T> inline void amax(T &a, const T &b) { if (a<b) a=b; }
 
LL my_sqrt(LL x) {
    LL hi = x, lo = 0;
    while (hi -lo > 1) {
	LL m = (hi + lo) >> 1;
	(m*m <= x? lo : hi) = x;
    }
    return lo;
}
int Q;
LL N;
 
int main() {
 
    scanf("%d", &Q);
    REP ($, Q) {
	scanf("%lld", &N);
	if (N == 1) {
	    puts("0 0");
	    continue;
	}
 
	N--;
	LL lo = 0, hi = 1LL<<31;
	while (hi - lo > 1) {
	    LL m = (hi + lo) >> 1;
	    (m * (m+1) * 2 < N ? lo : hi) = m;
	}
	LL p = hi;
 
	LL b = (p-1)*p*2 + 1;
 
	if (N-b < 2*p) {
	    if (N % 2) printf("%lld %lld\n", -p+(N-b)/2, (N-b)/2);
	    else printf("%lld %lld\n", -p+(N-b+1)/2, -(N-b+1)/2);
	} else {
	    if (N % 2) printf("%lld %lld\n", (N-b-2*p)/2, p - (N-b-2*p)/2);
	    else printf("%lld %lld\n", (N-b-2*p+1)/2, -p + (N-b-2*p + 1)/2);
	}
    }
    
    return 0;
}

Submission

Task問題 B - n-th Points
User nameユーザ名 wuyiqi
Created time投稿日時
Language言語 C++11 (GCC 4.8.1)
Status状態 AC
Score得点 100
Source lengthソースコード長 1354 Byte
File nameファイル名
Exec time実行時間 154 ms
Memory usageメモリ使用量 916 KB

Compiler messageコンパイルメッセージ

./Main.cpp: In function ‘int main()’:
./Main.cpp:33:20: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &Q);
^
./Main.cpp:35:19: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld", &N);
^

Test case

Set

Set name Score得点 / Max score Cases
Sample - subtask0_sample_01.txt
All 100 / 100 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

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
subtask0_sample_01.txt AC 28 ms 788 KB
subtask1_large_01.txt AC 149 ms 812 KB
subtask1_mini01.txt AC 89 ms 788 KB
subtask1_random01.txt AC 105 ms 788 KB
subtask1_random02.txt AC 127 ms 820 KB
subtask1_random03.txt AC 130 ms 788 KB
subtask1_random04.txt AC 149 ms 888 KB
subtask1_random05.txt AC 151 ms 880 KB
subtask1_random06.txt AC 148 ms 916 KB
subtask1_random07.txt AC 153 ms 792 KB
subtask1_random08.txt AC 154 ms 796 KB