답안 #839092

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
839092 2023-08-28T15:48:33 Z 42kangaroo Group Photo (JOI21_ho_t3) C++17
0 / 100
1 ms 340 KB
//
// Created by 42kangaroo on 28/08/2023.
//
#include "bits/stdc++.h"

using namespace std;

#define int long long

vector<vector<int>> weightF(vector<int>& a) {
	// get inversion direction
	vector<vector<bool>> dI(a.size(), vector<bool>(a.size()));
	for (int i = 0; i < a.size(); ++i) {
		for (int j = 0; j < i; ++j) {
			if (a[i] > a[j]) {
				dI[a[i]][a[j]] = true; // second is greater
			} else {
				dI[a[j]][a[i]] = false;
			}
		}
	}
	// add to new as dif array
	vector<vector<int>> cD(a.size() + 1, vector<int>(a.size() + 1, 0));
	for (int i = 1; i < cD.size(); ++i) {
		int le = 0;
		for (int j = 1; j < i; ++j) {
			cD[j][i] = (dI[i - 1][j - 1] ? 1 : -1);
			le += !dI[i][j];
		}
		cD[i][i] = le;
	}
	// calc dif array
	vector<vector<int>> c(a.size() + 1, vector<int>(a.size() + 1, 0));
	for (int i = 1; i < c.size(); ++i) {
		for (int j = i; j >= 0; --j) {
			if (j != c.size() - 1) c[j][i] += c[j + 1][i];
			c[j][i] += c[j][i - 1];
		}
	}
	return c;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n; cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	vector<int> dp(n + 1, -1);
	dp[0] = 0;
	vector<vector<int>> c = weightF(a);
	for (int i = 1; i <= n; ++i) {
		for (int j = 0; j < i; ++j) {
			dp[i] = min(dp[i], dp[j] + c[j][i]);
		}
	}
	cout << dp[n];
}

Compilation message

Main.cpp: In function 'std::vector<std::vector<long long int> > weightF(std::vector<long long int>&)':
Main.cpp:13:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   13 |  for (int i = 0; i < a.size(); ++i) {
      |                  ~~^~~~~~~~~~
Main.cpp:24:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::vector<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |  for (int i = 1; i < cD.size(); ++i) {
      |                  ~~^~~~~~~~~~~
Main.cpp:34:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::vector<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |  for (int i = 1; i < c.size(); ++i) {
      |                  ~~^~~~~~~~~~
Main.cpp:36:10: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::vector<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |    if (j != c.size() - 1) c[j][i] += c[j + 1][i];
      |        ~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 340 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 340 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 340 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 340 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 340 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -