이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int lmt = 5005;
const long long MOD = 1000000007;
#define f first
#define S second
#define ll long long
#define ld long double
#define ull unsigned long long
#define forn(i, n) for(int i = 0; i < int(n); i++)
#define for1(i, n) for(int i = 1; i < int(n); i++)
#define forv(i,a,n) for(int i = int(a); i < int(n); i++)
#define rof(i, n) for(int i = int(n); i >= 0; i--)
#define rofv(i,a,n) for(int i = int(n); i >= int(a); i--)
#define pb push_back
#define ins insert
#define pai pair<int, int>
#define pal pair<long long, long long>
#define vi vector<int>
#define vl vector<long long>
#define vld vector<long double>
int dp[lmt];
int n, p[lmt];
/*
struct wer{
int a, b;
};
bool operator < (const wer &a, const wer &b){
return a.a < b.a;
}*/
vi a[lmt];
int precalc[lmt][lmt];
int buc[lmt][lmt];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin>>n;
for1(i, n+1){
cin>>p[i];
}
for1(i,n+1){
for1(j,n+1){
if(p[j]>=i){
buc[i][p[j]] = a[i].size();
a[i].pb(p[j]);
}
}
}
for1(i,n+1){
int j = i;
int D = 0;
vi r;
while(j<=n){
D += buc[i][j];
for(int g = 0; g < r.size(); g++){
if(r[g]>buc[i][j]){
D--;
}
}
precalc[i][j] = D;
r.pb(buc[i][j]);
j++;
}
}
memset(dp, 1, sizeof(dp));
dp[n+1]=0;
for(int i = n; i > 0; i--){
for(int j = i; j <= n; j++){
dp[i] = min(dp[i], precalc[i][j] + dp[j+1]);
}
}
cout<<dp[1];
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
Main.cpp: In function 'int main()':
Main.cpp:57:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
57 | for(int g = 0; g < r.size(); g++){
| ~~^~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |