| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1334136 | SpyrosAliv | Gift Boxes (EGOI25_giftboxes) | C++20 | 142 ms | 20912 KiB |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int t, n; cin >> t >> n;
vector<int> cnt(t+1, 0);
vector<int> arr(n+1);
for (int i = 1; i <= n; i++) {
cin >> arr[i];
arr[i]++;
cnt[arr[i]]++;
}
priority_queue<pair<int, int>> pq;
for (int i = 1; i <= t; i++) {
pq.push({cnt[i], i});
}
int bestL = 1, bestR = n;
int l = 1, r = 1;
cnt[arr[1]]--;
pq.push({cnt[arr[1]], arr[1]});
while (l <= n) {
if (l > r) {
cnt[arr[r]]++;
pq.push({cnt[arr[r]], arr[r]});
r++;
continue;
}
while (!pq.empty() && cnt[pq.top().second] != pq.top().first) {
pq.pop();
}
if (pq.top().first <= 1) {
if (r - l + 1 <= bestR - bestL + 1) {
bestL = l;
bestR = r;
}
cnt[arr[l]]++;
pq.push({cnt[arr[l]], arr[l]});
l++;
}
else {
if (r == n) break;
r++;
cnt[arr[r]]--;
pq.push({cnt[arr[r]], arr[r]});
}
}
cout << bestL - 1 << " " << bestR - 1 << "\n";
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
solve();
return 0;
}| # | 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... | ||||
