답안 #529521

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
529521 2022-02-23T05:58:30 Z abc864197532 Group Photo (JOI21_ho_t3) C++17
44 / 100
5000 ms 3120 KB
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define pb push_back
#define eb emplace_back
#define pii pair<int,int>
#define X first
#define Y second
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
void abc() {cout << endl;}
template <typename T, typename ...U> void abc(T i, U ...j) {
	cout << i << ' ', abc(j...);
}
template <typename T> void printv(T l, T r) {
	for (; l != r; ++l) cout << *l << " \n"[l + 1 == r];
}
#ifdef Doludu
#define test(x...) abc("[" + string(#x) + "]", x)
#define owo freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#else
#define test(x...) void(0)
#define owo ios::sync_with_stdio(false), cin.tie(0)
#endif
const int N = 200000;

int main () {
	owo;
	int n;
	cin >> n;
	vector <int> p(n);
	for (int i = 0; i < n; ++i)
		cin >> p[i], --p[i];
	vector <int> dp(n + 1, 1 << 30);
	vector <vector <int>> cost(n + 1, vector <int> (n + 1, 0));
	for (int r = 1; r <= n; ++r) {
		vector <int> ord;
		for (int i = 0; i < n; ++i) if (p[i] < r)
			ord.pb(p[i]);
		for (int l = r - 1; ~l; --l) {
			vector <int> v = ord;
			int res = 0;
			for (int i = l; i < r; ++i) {
				int pos = find(all(v), i) - v.begin();
				res += int(v.size()) - pos - 1;
				v.erase(v.begin() + pos);
			}
			cost[l][r] = res;
		}
	}
	dp[0] = 0;
	for (int i = 1; i <= n; ++i) {
		for (int j = 0; j < i; ++j) {
			// max at postion j
			dp[i] = min(dp[i], dp[j] + cost[j][i]);
		}
	}
	cout << dp[n] << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 316 KB Output is correct
2 Correct 0 ms 312 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 304 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 316 KB Output is correct
2 Correct 0 ms 312 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 304 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 312 KB Output is correct
13 Correct 1 ms 324 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 0 ms 316 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 316 KB Output is correct
2 Correct 0 ms 312 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 304 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 312 KB Output is correct
13 Correct 1 ms 324 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 0 ms 316 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 53 ms 484 KB Output is correct
22 Correct 50 ms 476 KB Output is correct
23 Correct 50 ms 484 KB Output is correct
24 Correct 55 ms 600 KB Output is correct
25 Correct 50 ms 488 KB Output is correct
26 Correct 50 ms 480 KB Output is correct
27 Correct 50 ms 460 KB Output is correct
28 Correct 52 ms 484 KB Output is correct
29 Correct 53 ms 492 KB Output is correct
30 Correct 52 ms 460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 316 KB Output is correct
2 Correct 0 ms 312 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 304 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 312 KB Output is correct
13 Correct 1 ms 324 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 0 ms 316 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 53 ms 484 KB Output is correct
22 Correct 50 ms 476 KB Output is correct
23 Correct 50 ms 484 KB Output is correct
24 Correct 55 ms 600 KB Output is correct
25 Correct 50 ms 488 KB Output is correct
26 Correct 50 ms 480 KB Output is correct
27 Correct 50 ms 460 KB Output is correct
28 Correct 52 ms 484 KB Output is correct
29 Correct 53 ms 492 KB Output is correct
30 Correct 52 ms 460 KB Output is correct
31 Execution timed out 5041 ms 3120 KB Time limit exceeded
32 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 316 KB Output is correct
2 Correct 0 ms 312 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 304 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 312 KB Output is correct
13 Correct 1 ms 324 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 0 ms 316 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 53 ms 484 KB Output is correct
22 Correct 50 ms 476 KB Output is correct
23 Correct 50 ms 484 KB Output is correct
24 Correct 55 ms 600 KB Output is correct
25 Correct 50 ms 488 KB Output is correct
26 Correct 50 ms 480 KB Output is correct
27 Correct 50 ms 460 KB Output is correct
28 Correct 52 ms 484 KB Output is correct
29 Correct 53 ms 492 KB Output is correct
30 Correct 52 ms 460 KB Output is correct
31 Execution timed out 5041 ms 3120 KB Time limit exceeded
32 Halted 0 ms 0 KB -