結果
| 問題 |
No.1274 楽しい格子点
|
| コンテスト | |
| ユーザー |
LayCurse
|
| 提出日時 | 2020-10-30 21:35:06 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 3,604 bytes |
| コンパイル時間 | 2,533 ms |
| コンパイル使用メモリ | 212,004 KB |
| 最終ジャッジ日時 | 2025-01-15 16:51:13 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 54 WA * 3 |
ソースコード
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline int my_getchar_unlocked(){
static char buf[1048576];
static int s = 1048576;
static int e = 1048576;
if(s == e && e == 1048576){
e = fread_unlocked(buf, 1, 1048576, stdin);
s = 0;
}
if(s == e){
return EOF;
}
return buf[s++];
}
inline void rd(long long &x){
int k;
int m=0;
x=0;
for(;;){
k = my_getchar_unlocked();
if(k=='-'){
m=1;
break;
}
if('0'<=k&&k<='9'){
x=k-'0';
break;
}
}
for(;;){
k = my_getchar_unlocked();
if(k<'0'||k>'9'){
break;
}
x=x*10+k-'0';
}
if(m){
x=-x;
}
}
struct MY_WRITER{
char buf[1048576];
int s;
int e;
MY_WRITER(){
s = 0;
e = 1048576;
}
~MY_WRITER(){
if(s){
fwrite_unlocked(buf, 1, s, stdout);
}
}
}
;
MY_WRITER MY_WRITER_VAR;
void my_putchar_unlocked(int a){
if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){
fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout);
MY_WRITER_VAR.s = 0;
}
MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a;
}
inline void wt_L(char a){
my_putchar_unlocked(a);
}
int WRITER_DOUBLE_DIGIT = 15;
inline int writerDigit_double(){
return WRITER_DOUBLE_DIGIT;
}
inline void writerDigit_double(int d){
WRITER_DOUBLE_DIGIT = d;
}
inline void wt_L(double x){
const int d = WRITER_DOUBLE_DIGIT;
int k;
int r;
double v;
if(x!=x || (x==x+1 && x==2*x)){
my_putchar_unlocked('E');
my_putchar_unlocked('r');
my_putchar_unlocked('r');
return;
}
if(x < 0){
my_putchar_unlocked('-');
x = -x;
}
x += 0.5 * pow(0.1, d);
r = 0;
v = 1;
while(x >= 10*v){
v *= 10;
r++;
}
while(r >= 0){
r--;
k = floor(x / v);
if(k >= 10){
k = 9;
}
if(k <= -1){
k = 0;
}
x -= k * v;
v *= 0.1;
my_putchar_unlocked(k + '0');
}
if(d > 0){
my_putchar_unlocked('.');
v = 1;
for(r=(0);r<(d);r++){
v *= 0.1;
k = floor(x / v);
if(k >= 10){
k = 9;
}
if(k <= -1){
k = 0;
}
x -= k * v;
my_putchar_unlocked(k + '0');
}
}
}
inline void wt_L(const char c[]){
int i=0;
for(i=0;c[i]!='\0';i++){
my_putchar_unlocked(c[i]);
}
}
template<class T, class U> inline T GCD_L(T a, U b){
T r;
while(b){
r=a;
a=b;
b=r%a;
}
return a;
}
template<class S, class T> inline S chmax(S &a, T b){
if(a<b){
a=b;
}
return a;
}
int main(){
long long A;
rd(A);
long long B;
rd(B);
long long i;
long long j;
long long g;
double res = 0;
if(A==0 && B==0){
wt_L("0.25");
wt_L('\n');
return 0;
}
{
auto Lj4PdHRW = (-A);
auto KL2GvlyY = ( -B);
chmax(A, Lj4PdHRW);
chmax(B, KL2GvlyY);
}
g =GCD_L(A, B);
if(A==0 || B==0){
for(i=(1);i<(50);i+=(g)){
res += pow(i+1, -(i+1));
}
}
else{
for(i=(1);i<(50);i+=(g)){
for(j=(1);j<(50);j+=(g)){
if(A%2 && B%2 && (i-1)%(2*g) != (j-1)%(2*g)){
continue;
}
res += pow(i+j, -(i+j));
}
}
}
wt_L(res);
wt_L('\n');
return 0;
}
// cLay varsion 20201026-1
// --- original code ---
// {
// ll @A, @B, i, j, g;
// double res = 0;
//
// if(A==0 && B==0) wt("0.25"), return 0;
//
// (A, B) >?= (-A, -B);
// g = gcd(A,B);
//
// if(A==0 || B==0){
// rep(i,1,50,g) res += pow(i+1, -(i+1));
// } else {
// rep(i,1,50,g) rep(j,1,50,g){
// if(A%2 && B%2 && (i-1)%(2*g) != (j-1)%(2*g)) continue;
// res += pow(i+j, -(i+j));
// }
// }
//
// wt(res);
// }
LayCurse