| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 830507 | RaresFelix | Group Photo (JOI21_ho_t3) | C++17 | 817 ms | 468 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int MN = 5001;
const int INF = 1e9;
struct BIT {
vector<int> S;
BIT(int n) : S(n) {}
void update(int p, int v) {
while(p < S.size()) {
S[p] += v;
p += p & -p;
}
}
int query(int p) {
int re = 0;
while(p) {
re += S[p];
p -= p & -p;
}
return re;
}
int query(int st, int dr) {
return (st <= 0 ? query(dr) : (query(dr) - query(st - 1)));
}
void clear() {
fill(S.begin(), S.end(), 0);
}
void afis(int n, string mes) {
cout << mes;
for(int i = 1; i <= n; ++i)
cout << query(i, i) << " ";
cout << "\n";
}
};
BIT Activ(MN), Inv(MN), InSol(MN);
int n, A[MN], DP[MN], Rank[MN];
int main() {
cin >> n;
for(int i = 1; i <= n; ++i) {
cin >> A[i];
Rank[A[i]] = i;
}
DP[0] = 0;
for(int i = 1; i <= n; ++i) {
DP[i] = INF;
}
for(int i = 0; i <= n; ++i) {
///adaug asupra solutiei de lungime i
for(int j = 1; j <= n; ++j) {
Activ.update(j, 1);
}
for(int j = 1; j <= i; ++j)
Activ.update(Rank[j], -1); /// luate
int cost = 0;
for(int j = i + 1; j <= n; ++j) {
cost += Activ.query(Rank[j] - 1) - InSol.query(Rank[j], n);
cost += Inv.query(Rank[j] - 1);
InSol.update(Rank[j], 1);
// printf("Din %d in %d\n", i, j);
// Inv.afis(n, "Inv: ");
// Activ.afis(n, "Activ: ");
// InSol.afis(n, "InSol: ");
// printf("costul e %d\n\n", cost);
Inv.update(Rank[j], 1);
Activ.update(Rank[j], -1);
DP[j] = min(DP[j], DP[i] + cost);
}
Activ.clear();
Inv.clear();
InSol.clear();
}
cout << DP[n] << "\n";
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
| # | 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... | ||||
