結果

問題 No.370 道路の掃除
ユーザー srup٩(๑`н´๑)۶srup٩(๑`н´๑)۶
提出日時 2016-05-24 19:51:17
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,773 bytes
コンパイル時間 868 ms
コンパイル使用メモリ 87,512 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-16 12:21:59
合計ジャッジ時間 1,662 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 WA -
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 WA -
testcase_10 AC 2 ms
5,376 KB
testcase_11 WA -
testcase_12 AC 1 ms
5,376 KB
testcase_13 WA -
testcase_14 AC 1 ms
5,376 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 2 ms
5,376 KB
testcase_20 WA -
testcase_21 AC 2 ms
5,376 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 2 ms
5,376 KB
testcase_26 WA -
testcase_27 AC 2 ms
5,376 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 2 ms
5,376 KB
testcase_32 WA -
testcase_33 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:36:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   36 |         scanf("%d %d", &n, &m);
      |         ~~~~~^~~~~~~~~~~~~~~~~
main.cpp:42:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   42 |                 scanf("%d", &tmp);
      |                 ~~~~~^~~~~~~~~~~~

ソースコード

diff #

/*
*/
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
using namespace std;

typedef long long ll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<pint> vpint;

#define mp make_pair
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)

int dx[4] = {1, 0, 0, -1};
int dy[4] = {0, 1, -1, 0};

int main(void){
	int n, m;
	scanf("%d %d", &n, &m);
	int tmp_sei[m];
	int tmp_fu[m];

	int sei = 0, zero = 0, fu = 0, tmp;
	rep(i, m){
		scanf("%d", &tmp);
		if (tmp > 0){
			tmp_sei[sei] = tmp;
			sei++;
		}else if(tmp == 0){
			zero++;
		}else{
			tmp_fu[fu] = tmp;
			fu++;
		}
	}
	vector<int> d_sei(sei);
	vector<int> d_fu(fu);

	rep(i, sei)
		d_sei[i] = tmp_sei[i];

	rep(i, fu)
		d_fu[i] = tmp_fu[i];

	//大きくなるように
	sort(d_sei.begin(), d_sei.end());
	//小さくなるように
	sort(d_fu.begin(), d_fu.end(), greater<int>());

	int ans = 10000000;
	int sum;

	if (fu >= n - zero){
		//負だけからとる時
		sum = d_fu[n - zero - 1] * -1;
		ans = min(ans, sum);
	}
	if(sei >= n - zero){
		//正だけからとる時
		sum = d_sei[n - zero - 1];
		ans = min(ans, sum); 
	}

	//両方から取る時
	reps(i, 1 , n - zero) //i個
	{
		if(0 <=i - 1 && i - 1 <= fu - 1 && 0 <= n - i - 1 && n - i - 1 <= sei){
			if (d_fu[i - 1] <= d_sei[n - i - 1]){
				sum = d_fu[i - 1] * -2 + d_sei[n - i - 1];
			}else{
				sum = (d_fu[i - 1] * -1 + d_sei[n - i - 1] * 2);
			}
		ans = min(ans, sum);
		}
	}
	printf("%d\n", ans);
	return 0;
}
0