CODE FESTIVAL 2016 Grand Final

Submission #1335854

Source codeソースコード

#include <iostream>
#include <cstdio>
#include <map>
#include <set>
#include <queue>
#include <vector>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#define rep(i,a,b) for(int i = a; i <= b; i++)
#define dep(i,a,b) for(int i = a; i >= b; i--) 
#define Rep(i,a) for(int i = 0; i < a; i++)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define ab(x) ((x) < 0 ? -(x) : (x))
using namespace std;
typedef long long LL;
typedef map<int, int>::iterator mit;
typedef set<int>::iterator sit;
typedef pair<int, int> pii;
#define x first
#define y second
const int N = 5010;
const LL inf = 1LL << 60;
int n, l[N], r[N], id[N];
LL f[N][N], g[N][N];
inline bool cmp(const int &a, const int &b) { return l[a] + r[a] < l[b] + r[b]; }
int main() {
	scanf("%d",&n);
	rep(i,1,n) scanf("%d%d", l + i, r + i), swap(l[i], r[i]);
	rep(i,1,n) id[i] = i; sort(id + 1, id + n + 1, cmp);
	f[0][0] = 0; rep(j,1,n) f[0][j] = inf;
	int cl = n >> 1, cr = n >> 1;
	rep(i,1,n) {
		int x = id[i];
		rep(j,0,i) {
			f[i][j] = inf;
			if (j - 1 >= 0) 
				f[i][j] = min(f[i][j], f[i - 1][j - 1] + l[x] + 1LL * (l[x] + r[x]) * (cl - j));
			f[i][j] = min(f[i][j], f[i - 1][j] + r[x] + 1LL * (l[x] + r[x]) * (cr - (i - j)));
		}
		rep(j,i+1,n) f[i][j] = inf;
	}

	if (!(n & 1)) printf("%lld\n",f[n][n / 2]);
	else {
		g[n+1][0] = 0; rep(j,1,n) g[n+1][j] = inf;
		dep(i,n,1) {
			int x = id[i];
			rep(j,0,n - i + 1) {
				g[i][j] = inf;
				if (j - 1 >= 0) g[i][j] = min(g[i][j], g[i + 1][j - 1] + l[x] + 1LL * (l[x] + r[x]) * (j - 1));
				else g[i][j] = min(g[i][j], g[i + 1][j] + r[x] + 1LL * (l[x] + r[x]) * ((n - i + 1) - j - 1));
			}
			rep(j,n-i+2,n) g[i][j] = inf;
		}
		LL ans = inf;
		rep(i,1,n) {
			int x = id[i], t = n >> 1;
			LL tot = 1LL * t * (l[x] + r[x]); 
			rep(j,0,t) ans = min(ans, tot + f[i - 1][j] + g[i + 1][t - j]);
		}
		cout <<ans<<endl; 
	}
	return 0;
}

Submission

Task問題 F - Intervals
User nameユーザ名 WuHongxun
Created time投稿日時
Language言語 C++14 (GCC 5.4.1)
Status状態 WA
Score得点 0
Source lengthソースコード長 1939 Byte
File nameファイル名
Exec time実行時間 ms
Memory usageメモリ使用量 -

Compiler messageコンパイルメッセージ

./Main.cpp: In function ‘int main()’:
./Main.cpp:29:16: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&n);
^
./Main.cpp:30:58: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
rep(i,1,n) scanf("%d%d", l + i, r + i), swap(l[i], r[i]);
^

Test case

Set

Set name Score得点 / Max score Cases
Sample - example0.txt,example1.txt
All 0 / 1000 000.txt,001.txt,002.txt,003.txt,004.txt,005.txt,006.txt,007.txt,008.txt,009.txt,010.txt,011.txt,012.txt,013.txt,014.txt,015.txt,016.txt,017.txt,018.txt,019.txt,020.txt,021.txt,022.txt,023.txt,024.txt,025.txt,026.txt,027.txt,028.txt,029.txt,030.txt,031.txt,032.txt,033.txt,034.txt,035.txt,036.txt,037.txt,038.txt,039.txt,040.txt,041.txt,042.txt,example0.txt,example1.txt

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
000.txt AC 82 ms 197632 KB
001.txt AC 25 ms 84224 KB
002.txt AC 82 ms 197632 KB
003.txt MLE
004.txt AC 82 ms 197632 KB
005.txt WA
006.txt AC 82 ms 197632 KB
007.txt AC 49 ms 137472 KB
008.txt AC 82 ms 197632 KB
009.txt AC 17 ms 61696 KB
010.txt AC 82 ms 197632 KB
011.txt AC 44 ms 129280 KB
012.txt AC 82 ms 197632 KB
013.txt AC 15 ms 55552 KB
014.txt AC 82 ms 197632 KB
015.txt WA
016.txt AC 82 ms 197632 KB
017.txt AC 66 ms 170240 KB
018.txt AC 82 ms 197632 KB
019.txt MLE
020.txt AC 2 ms 2304 KB
021.txt AC 2 ms 2304 KB
022.txt AC 82 ms 197632 KB
023.txt AC 82 ms 197632 KB
024.txt AC 82 ms 197632 KB
025.txt AC 82 ms 197632 KB
026.txt AC 82 ms 197632 KB
027.txt AC 82 ms 197632 KB
028.txt AC 82 ms 197632 KB
029.txt AC 82 ms 197632 KB
030.txt AC 82 ms 197632 KB
031.txt AC 82 ms 197632 KB
032.txt AC 82 ms 197632 KB
033.txt AC 82 ms 197632 KB
034.txt AC 82 ms 197632 KB
035.txt AC 82 ms 197632 KB
036.txt AC 82 ms 197632 KB
037.txt AC 82 ms 197632 KB
038.txt AC 82 ms 197632 KB
039.txt AC 82 ms 197632 KB
040.txt AC 82 ms 197632 KB
041.txt AC 82 ms 197632 KB
042.txt AC 82 ms 197632 KB
example0.txt AC 2 ms 2304 KB
example1.txt AC 2 ms 4352 KB