Submission #777445

# Submission time Handle Problem Language Result Execution time Memory
777445 2023-07-09T09:10:45 Z a_aguilo Sails (IOI07_sails) C++14
25 / 100
1000 ms 65536 KB
#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;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 312 KB Output is correct
2 Correct 14 ms 316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1064 ms 1492 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 27 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 29 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 39 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 47 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 61 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 62 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 67 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -