이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define mp make_pair
#define mt make_tuple
#define all(x) x.begin(), x.end()
#define ff first
#define ss second
using namespace std;
template <typename T>
using matrix = vector<vector<T>>;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll INFL = (1LL<<62)-1;
const int INF = (1<<30)-1;
const double EPS = 1e-7;
const int MOD = 1e9 + 7;
const int RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();
const int MAXN = 1e6+1;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vector<int> v(n+1);
for(int i = 1; i <= n; i++)
cin >> v[i];
vector<int> o(n+1);
iota(all(o),0);
stable_sort(1+all(o),[&](int a, int b){return v[a] < v[b];});
vector<pii> dp(n+1);
auto solve =[&](int limit){
priority_queue<pii> q;
q.push({-INF,-INF});
int ptr = -1;
for(int i = 1; i <= n; i++){
while(ptr < i-v[o[i]]){
ptr++;
if(ptr>=0)
q.push({dp[ptr].ff,ptr});
}
ptr = min(ptr,i-v[o[i]]);
int timer = 0;
while(q.top().ss > ptr || (q.top().ss!=-INF && q.top().ss < i-limit))
q.pop();
dp[i] = q.top();
dp[i].ff++;
}
};
solve(INF);
int goal = dp[n].ff;
int ini = 1, fim = n;
while(ini!=fim){
int m = (ini+fim)>>1;
solve(m);
if(dp[n].ff == goal)
fim = m;
else ini = m+1;
}
solve(ini);
matrix<int> resp;
resp.reserve(dp[n].ff);
int id = n;
while(id){
//cout << id << ' ' << dp[id].ss << endl;
resp.push_back({});
for(int i = id; i > dp[id].ss; i--){
resp.back().push_back(o[i]);
}
id = dp[id].ss;
}
cout << resp.size() << '\n';
for(vector<int>& i : resp){
cout << i.size() << ' ';
for(int j : i )
cout << j << ' ';
cout << '\n';
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
tea.cpp: In lambda function:
tea.cpp:51:17: warning: unused variable 'timer' [-Wunused-variable]
51 | int timer = 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |