# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1281263 | tunademayo | Stone Arranging 2 (JOI23_ho_t1) | C++20 | 1 ms | 572 KiB |
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
const bool Multitest = 0;
const int N = 2e5 + 10;
int cnt[N]; stack<pair<int, int>> t;
int a[N], n;
void work()
{
cin >> n;
for(int i = 1 ; i <= n ; i++)
{
cin >> a[i];
}
for(int i = 1 ; i <= n ; i++)
{
cerr << i << '\n';
if(cnt[a[i]] == 0)
{
cnt[a[i]] = 1;
}
else
{
while(true)
{
pair<int, int> x = t.top(); t.pop();
if(x.fi == a[i])
{
break;
}
else
{
cnt[x.fi] = 0;
}
}
}
cnt[a[i]]++;
t.push({a[i], cnt[a[i]]});
}
int last = n;
while(!t.empty())
{
pair<int, int> x = t.top(); t.pop();
int tmp = last;
last -= x.se;
for(int i = last + 1 ; i <= tmp ; i++) a[i] = x.fi;
}
for(int i = 1 ; i <= n ; i++) cout << a[i] << ' ';
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
if(fopen("task.inp", "r"))
{
freopen("task.inp", "r", stdin);
freopen("task.out", "w", stdout);
}
int q = 1;
if(Multitest) cin >> q;
while(q--) work();
}
컴파일 시 표준 에러 (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... |