結果

問題 No.4 おもりと天秤
ユーザー tsuishitsuishi
提出日時 2021-02-25 12:56:02
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 2,392 bytes
コンパイル時間 1,082 ms
コンパイル使用メモリ 30,968 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-26 03:16:57
合計ジャッジ時間 2,055 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 1 ms
4,348 KB
testcase_11 AC 1 ms
4,348 KB
testcase_12 AC 1 ms
4,348 KB
testcase_13 AC 1 ms
4,348 KB
testcase_14 AC 1 ms
4,348 KB
testcase_15 AC 1 ms
4,348 KB
testcase_16 AC 1 ms
4,348 KB
testcase_17 AC 1 ms
4,348 KB
testcase_18 AC 1 ms
4,348 KB
testcase_19 AC 1 ms
4,348 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 1 ms
4,348 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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;
      |         ^~~~~~

ソースコード

diff #

#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;
}

0