結果

問題 No.370 道路の掃除
ユーザー yuho0819yuho0819
提出日時 2016-09-04 10:52:35
言語 C++11
(gcc 13.3.0)
結果
RE  
実行時間 -
コード長 992 bytes
コンパイル時間 182 ms
コンパイル使用メモリ 24,320 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-11-15 20:08:26
合計ジャッジ時間 4,874 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other WA * 4 RE * 30
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:5:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    5 |         scanf("%d %d",&a,&s);
      |         ~~~~~^~~~~~~~~~~~~~~
main.cpp:13:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   13 |                 scanf("%d",&d);
      |                 ~~~~~^~~~~~~~~
main.cpp:35:28: warning: ‘z’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   35 |                 for(j=i+1;j<z;j++){
      |                           ~^~

ソースコード

diff #

#include<stdio.h>
int main(void)
{
	int a,s,d,lo[10000],hi[10000],h,i,j,k,z,x,c,g,f;
	scanf("%d %d",&a,&s);
	h=0;
	j=0;
	for(i=0;i<10000;i++){
		lo[i]=-1;
		hi[i]=-1;
	}
	for(i=0;i<s;i++){
		scanf("%d",&d);
		if(d<0){
			lo[h]=d;
			h++;
		}
		if(d>0){
			hi[z]=d;
			z++;
		}
		if(d==0)
			a--;
	}
	for(i=0;i<h;i++){
		for(j=i+1;j<h;j++){
			if(lo[i]<lo[j]){
				k=lo[i];
				lo[i]=lo[j];
				lo[j]=k;
			}
		}
	}
	for(i=0;i<z;i++){
		for(j=i+1;j<z;j++){
			if(hi[i]>hi[j]){
				k=hi[i];
				hi[i]=hi[j];
				hi[j]=k;
			}
		}
	}
	/*for(i=0;i<h;i++)
		printf("low %d=%d\n",i,lo[i]);
	for(i=0;i<z;i++)
		printf("high %d=%d\n",i,hi[i]);*/
	g=2100000000;
	x=a;
	f=0;
	for(i=0;i<=a;i++){
		k=0;
		c=0;
		for(j=0;j<x;j++){
			k+=lo[j]*-1;
		}
		for(j=0;j<f;j++){
			c+=hi[j];
		}
		//printf("x==%d f==%d\n",x,f);
		x--;
		f++;
		//printf("k*2=%d c*2=%d c=%d k=%d\n",k*2+c,c*2+k,c,k);
		if(k>=0&&c>=0){
			if(g>k*2+c)
				g=k*2+c;
			if(g>c*2+k)
				g=c*2+k;
		}
	}
	printf("%d\n",g);
	return 0;
}
0