#include<bits/stdc++.h>
using namespace std;
int N;
long long sol, ans;
const int maxN = 100002;
const int maxH = 100002;
int H[maxN];
int K[maxN];
int occupation[maxH];
void backtracking(int mast, int leftSails, int h){
if(h == 0){
if(mast == 0){
sol = min(sol, ans);
return;
}
else backtracking(mast-1, K[mast-1], H[mast-1]);
}else{
if(leftSails == h){
ans += occupation[h];
occupation[h]++;
backtracking(mast, leftSails-1, h-1);
occupation[h]--;
ans -= occupation[h];
}else if(leftSails){
backtracking(mast, leftSails, h-1);
ans += occupation[h];
occupation[h]++;
backtracking(mast, leftSails-1, h-1);
occupation[h]--;
ans -= occupation[h];
}else{
backtracking(mast-1, K[mast-1], H[mast-1]);
}
}
}
int main(){
sol = 1e18;
ans = 0;
cin >> N;
for(int i = 1; i <= N; ++i) cin >> H[i] >> K[i];
backtracking(N, K[N], H[N]);
cout << sol << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
312 KB |
Output is correct |
2 |
Correct |
14 ms |
316 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1064 ms |
1492 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
27 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
29 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
39 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
47 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
61 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
62 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
67 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |