結果
| 問題 | No.8024 等式 |
| コンテスト | |
| ユーザー |
akakimidori
|
| 提出日時 | 2018-08-02 01:20:11 |
| 言語 | C90(gcc15) (gcc 15.2.0) |
| 結果 |
CE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 2,171 bytes |
| 記録 | |
| コンパイル時間 | 115 ms |
| コンパイル使用メモリ | 28,508 KB |
| 最終ジャッジ日時 | 2026-02-24 00:57:52 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge5 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
main.c: In function 'calc':
main.c:87:3: error: C++ style comments are not allowed in ISO C90
87 | //operator
| ^
main.c:87:3: note: (this will be reported only once per input file)
ソースコード
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
typedef long long int int64;
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))
typedef struct fraction{
int64 nu;
int64 de;
} frac;
int64 gcd(int64 a,int64 b){
int64 r=a%b;
while(r>0){
a=b;b=r;r=a%b;
}
return b;
}
void add(frac *c,frac *a,frac *b){
int64 x=a->nu*b->de+a->de*b->nu;
if(x==0){
c->nu=0;
c->de=1;
return;
}
int64 y=a->de*b->de;
c->nu=x;
c->de=y;
return;
}
void sub(frac *c,frac *a,frac *b){
int64 x=a->nu*b->de-a->de*b->nu;
if(x==0){
c->nu=0;
c->de=1;
return;
}
int64 y=a->de*b->de;
c->nu=x;
c->de=y;
return;
}
void mul(frac *c,frac *a,frac *b){
int64 x=a->nu*b->nu;
if(x==0){
c->nu=0;
c->de=1;
return;
}
int64 y=a->de*b->de;
c->nu=x;
c->de=y;
return;
}
void division(frac *c,frac *a,frac *b){
int64 x=a->nu*b->de;
if(x==0){
c->nu=0;
c->de=1;
return;
}
int64 y=a->de*b->nu;
if(y<0){
y=-y;
x=-x;
}
c->nu=x;
c->de=y;
return;
}
frac stack[7];
int test;
int b[6];
int num;
int calc(int top){
if(top==1 && stack[0].nu%stack[0].de==0 && stack[0].nu/stack[0].de==test) return 1;
//operator
if(top>=2){
frac a=stack[top-2];
frac b=stack[top-1];
add(stack+top-2,&a,&b);if(calc(top-1)) return 1;
sub(stack+top-2,&a,&b);if(stack[top-2].nu>0 && calc(top-1)) return 1;
mul(stack+top-2,&a,&b);if(calc(top-1)) return 1;
if(b.nu!=0) division(stack+top-2,&a,&b);if(calc(top-1)) return 1;
stack[top-2]=a;
stack[top-1]=b;
}
//push
int i;
for(i=0;i<num;i++){
if(b[i]==0) continue;
int m=b[i];
b[i]=0;
stack[top].nu=m;
stack[top].de=1;
if(calc(top+1)) return 1;
b[i]=m;
}
return 0;
}
void run(void){
int n;
scanf("%d",&n);
int a[7];
int i;
for(i=0;i<n;i++) scanf("%d",a+i);
num=n-1;
for(i=0;i<n;i++){
int j;
int k=0;
for(j=0;j<n;j++){
if(i==j) continue;
b[k++]=a[j];
}
test=a[i];
if(calc(0)){
printf("YES\n");
return;
}
}
printf("NO\n");
}
int main(void){
run();
return 0;
}
akakimidori