이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL)
#define lli long long int
#define vi vector<int>
#define vlli vector<long long int>
#define pii pair<int, int>
#define plli pair<lli, lli>
#define rep(i, a, b) for(lli i = (a); i <= (b); i++)
#define repa(i, a, b) for(lli i = (a); i >= (b); i--)
#define repv(x, v) for(auto x : v)
#define debug(x) cout << #x << " = " << x << endl
#define debugsl(x) cout << #x << " = " << x << ", "
#define debugarr(x, a, b) cout << #x << " = ["; rep(ii, a, b) cout << x[ii] << ", "; cout << "]\n"
#define pb push_back
#define nl "\n"
#define MAX_N 5002
#define INF (1ll << 62)
lli n, h[MAX_N], dp[MAX_N];
lli costo(lli l, lli r){
vlli tmp;
lli pos, cnt, offset;
rep(i, 1, n) if (h[i] >= l) tmp.pb(h[i]);
cnt = offset = 0;
repa(i, r, l){
rep(j, 0, tmp.size() - 1) if (tmp[j] == i){ pos = j; break; }
repa(j, pos, offset + 1){
swap(tmp[j], tmp[j - 1]);
++cnt;
}
++offset;
}
return cnt;
}
int main()
{
fastio;
cin >> n;
rep(i, 1, n) cin >> h[i];
rep(i, 1, n){
dp[i] = INF;
rep(j, 0, i - 1){
dp[i] = min(dp[i], dp[j] + costo(j + 1, i));
}
}
cout << dp[n];
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
Main.cpp: In function 'long long int costo(long long int, long long int)':
Main.cpp:11:41: 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]
11 | #define rep(i, a, b) for(lli i = (a); i <= (b); i++)
| ^
Main.cpp:33:9: note: in expansion of macro 'rep'
33 | rep(j, 0, tmp.size() - 1) if (tmp[j] == i){ pos = j; break; }
| ^~~
Main.cpp:35:23: warning: 'pos' may be used uninitialized in this function [-Wmaybe-uninitialized]
35 | swap(tmp[j], tmp[j - 1]);
| ^
# | 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... |