結果
| 問題 |
No.4 おもりと天秤
|
| コンテスト | |
| ユーザー |
tsuishi
|
| 提出日時 | 2021-02-25 12:56:02 |
| 言語 | C (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 2,392 bytes |
| コンパイル時間 | 875 ms |
| コンパイル使用メモリ | 30,848 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-09-25 11:14:20 |
| 合計ジャッジ時間 | 1,580 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 23 |
コンパイルメッセージ
main.c: In function 'GETWORD':
main.c:33:21: warning: implicit declaration of function 'getchar_unlocked' [-Wimplicit-function-declaration]
33 | #define mygc(c) (c)=getchar_unlocked()
| ^~~~~~~~~~~~~~~~
main.c:34:61: note: in expansion of macro 'mygc'
34 | static char *GETWORD(char* str) {char c;char *cp;cp=&str[0];mygc(c);while(c!=EOF){if((c==' ')||(c=='\n'))break;*cp++=c;mygc(c);}*cp='\0';return &str[0];}
| ^~~~
main.c: In function 'main':
main.c:21:17: warning: implicit declaration of function 'putchar_unlocked' [-Wimplicit-function-declaration]
21 | #define mypc(d) putchar_unlocked(d)
| ^~~~~~~~~~~~~~~~
main.c:22:16: note: in expansion of macro 'mypc'
22 | #define PRINCR mypc('\n')
| ^~~~
main.c:73:9: note: in expansion of macro 'PRINCR'
73 | PRINCR;
| ^~~~~~
ソースコード
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
// Yukicoder №4 おもりと天秤 ★★☆
// https://yukicoder.me/problems/no/4
// ***********************
// for debug
#define DEBUGd
// -----------
#define NOP do{}while(0)
#ifdef DEBUG
#define TRACE(...) do{printf(__VA_ARGS__);fflush(stdout);}while(0)
#define TRACECR do{putchar_unlocked('\n');fflush(stdout);}while(0)
#else
#define TRACE(...) NOP
#define TRACECR NOP
#endif
#define mypc(d) putchar_unlocked(d)
#define PRINCR mypc('\n')
#define NOCR(strig) do{char *p;p=strchr(strig,'\n');if(p)*p='\0';}while(0)
// The out-of-date function
#define asctime(...) asctime_s(...)
#define ctime(...) ctime_s(...)
#define strlen(a) mystr_len(a)
#define Possible(a) printf("%s",((a)?"Possible":"Impossible"))
#define possible(a) printf("%s",((a)?"possible":"impossible"))
// for stdio
#define GETLINE(str) do{char *p;fgets(str,sizeof(str),stdin);p=strchr(str,'\n');if(p)*p='\0';}while(0)
#define mygc(c) (c)=getchar_unlocked()
static char *GETWORD(char* str) {char c;char *cp;cp=&str[0];mygc(c);while(c!=EOF){if((c==' ')||(c=='\n'))break;*cp++=c;mygc(c);}*cp='\0';return &str[0];}
#define GETINTS(a,b) {char s[34];int *ap=a;REP(i,b){GETWORD(s);*ap++=atoi(s);}}
static int GETLINEINT(void) {char s[34];GETLINE(s);return atoi(s);}
static int GETWORDINT(void) {char s[34];GETWORD(s);return atoi(s);}
static long GETWORDLONG(void) {char s[34];GETWORD(s);return atol(s);}
static long maxl(long a,long b){if(a>b){return a;}return b;}
#define mystr_len(str) mystr_len_lim(str,9999)
static int mystr_len_lim(char *str,int lim){int i=0;do{if(str[i]=='\0')break;i++;}while(i<lim);return i;}
#define SWAP(type,a,b) do{type _c;_c=a;a=b;b=_c;}while(0)
#define REP(a,b) for(int a=0;a<(int)(b);++a)
// **************************
bool weight[100*102];
int mono[100];
// **************************
int main( void ) {
int kosuu;
int val;
int sumw =0;
kosuu = GETLINEINT();
REP(i,100 * (kosuu + 1)) weight[i] = false;
weight[0] = true;
REP(i,kosuu) {
val = GETWORDINT();
sumw += val;
mono[i] = val;
}
TRACE("sumw = %d\n", sumw );
if( !(sumw & 1) ) {
// あり得る取り合わせ全列挙
REP(i,kosuu) {
for(int k = i*100+100; k >=0; --k) {
if( weight[ k ] ) weight[ k + mono[i] ] = true;
}
}
TRACE("lp\n");
}
possible( weight[ sumw / 2] );
PRINCR;
return 0;
}
tsuishi