답안 #52959

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
52959 2018-06-27T09:30:55 Z 0^0(#1376) 조교 (CEOI16_popeala) C++11
0 / 100
67 ms 37500 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n, t, s;
const ll inf = 0x3f3f3f3f3f3f3f3f;

int p[20005];
int r[55][20005];
int sum[20005];
int q[20005][55];
ll dp[2][20005][55];
int rr[55];
deque<int> dq[55];
long long query(int bit, int idx, int l, int r) {
	assert(idx >= 0 && idx <= n);
	for (int i = rr[idx] + 1; i <= r; i++) {
		while (!dq[idx].empty() && dp[bit][dq[idx].back()][idx] >= dp[bit][i][idx])dq[idx].pop_back();
		dq[idx].push_back(i);
	}
	rr[idx] = r;
	while (!dq[idx].empty() && dq[idx].front() < l)dq[idx].pop_front();
	if (l > r)return inf;
	assert(!dq[idx].empty());
	assert(dq[idx].front() >= 0 && dq[idx].front() <= t);
	return dp[bit][dq[idx].front()][idx];
}
void solve(int k) {
	int now = k & 1;
	int pre = 1 - now;
	for (int i = 0; i <= n; i++) {
		dp[now][0][i] = inf;
		dq[i].clear();
		rr[i] = -1;
	}
	for (int i = 1; i <= t; i++) {
		int c = n;
		long long val = inf;
		int ri = i;
		for (int j = 0; j<n; j++) {
			int le = ri - q[i][j] + 1;
			val = min(val, query(pre, c, le - 1, ri - 1) + c * sum[i]);
			c--;
			ri = le - 1;
		}
		val = min(val, query(pre, c, 0, ri - 1) );
		for (int j = 0; j <= n; j++)
			dp[now][i][j] = val - j * sum[i];
		if (i == t) printf("%lld\n", val);
	}
}
int main() {
	scanf("%d%d%d", &n, &t, &s);
	for (int i = 1; i <= t; i++) {
		scanf("%d", &p[i]);
		sum[i] = sum[i - 1] + p[i];
	}
	for (int i = 0; i < n; i++) {
		int cnt = 0;
		for (int j = 1; j <= t; j++) {
			scanf("%1d", &r[i][j]);
			if (r[i][j])cnt++;
			else cnt = 0;
			q[j][i] = cnt;
		}
	}
	for (int i = 1; i <= t; i++) {
		sort(q[i], q[i] + n);
		for (int j = 1; j < n; j++)
			q[i][j] -= q[i][j - 1];
	}
	memset(dp, 0x3f, sizeof(dp));
	for (int i = 0; i <= n; i++)
		dp[0][0][i] = 0;
	for (int i = 1; i <= s; i++)
		solve(i);
	return 0;
}

Compilation message

popeala.cpp: In function 'int main()':
popeala.cpp:52:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d%d", &n, &t, &s);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~
popeala.cpp:54:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &p[i]);
   ~~~~~^~~~~~~~~~~~~
popeala.cpp:60:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%1d", &r[i][j]);
    ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 17656 KB Output is correct
2 Runtime error 38 ms 35428 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# 결과 실행 시간 메모리 Grader output
1 Runtime error 46 ms 35984 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 67 ms 37500 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 17656 KB Output is correct
2 Runtime error 38 ms 35428 KB Execution killed with signal 11 (could be triggered by violating memory limits)