# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
500676 | 600Mihnea | Sails (IOI07_sails) | C++17 | 1099 ms | 2308 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int long long
int gauss(int x) {
return x * (x + 1) / 2;
}
struct Data {
int total;
int need;
};
bool operator < (Data a, Data b) {
return a.total < b.total;
}
const int N = (int) 1e5 + 7;
const int INF = (int) 1e18;
int n;
int cnt[N];
Data guys[N];
signed main() {
ios::sync_with_stdio(0); cin.tie(0);
//freopen ("input", "r", stdin);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> guys[i].total >> guys[i].need;
}
sort(guys + 1, guys + n + 1);
for (int i = 1; i <= n; i++) {
int total = guys[i].total;
int need = guys[i].need;
/// cnt e in ordine ordine descrescatoare
int L = total - need + 1;
int R = total;
int cntL = cnt[L];
int Lfirst = L, Llast = L;
/// binary search to find them
{
int low = 1, high = L;
while (low <= high) {
int mid = (low + high) / 2;
if (cnt[mid] == cnt[L]) {
Lfirst = mid;
high = mid - 1;
} else {
low = mid + 1;
}
}
}
{
int low = L, high = total;
while (low <= high) {
int mid = (low + high) / 2;
if (cnt[mid] == cnt[L]) {
Llast = mid;
low = mid + 1;
} else {
high = mid - 1;
}
}
}
int cntOfL = Llast - L + 1;
int firstActual = Lfirst;
int lastActual = Lfirst + cntOfL - 1;
for (int j = firstActual; j <= lastActual; j++) {
cnt[j]++;
}
for (int j = Llast + 1; j <= R; j++) {
cnt[j]++;
}
for (int j = 2; j <= total; j++) {
assert(cnt[j - 1] >= cnt[j]);
}
}
int total = 0;
for (int i = 1; i < N; i++) {
total += gauss(cnt[i] - 1);
}
cout << total << "\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... |
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |