# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1177201 | nguyn | Stone Arranging 2 (JOI23_ho_t1) | C++20 | 95 ms | 13384 KiB |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define F first
#define S second
#define pb push_back
#define pii pair<int,int>
const int N = 2e5 + 5;
int n;
int a[N];
map<int, int> pos;
int nxt[N];
signed main(){
ios_base::sync_with_stdio(false) ;
cin.tie(0) ; cout.tie(0) ;
if (fopen("INP.INP" ,"r")) {
freopen("INP.INP" ,"r" , stdin) ;
freopen("OUT.OUT" , "w" , stdout) ;
}
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = n; i >= 1; i--) {
if (!pos.count(a[i])) {
nxt[i] = i;
pos[a[i]] = i;
}
else {
nxt[i] = pos[a[i]];
pos[a[i]] = i;
}
}
int npos = 0;
int cur = a[1];
for (int i = 1; i <= n; i++) {
if (i > npos) {
cout << a[i];
cur = a[i];
npos = nxt[i];
}
else {
if (cur == a[i]) {
npos = nxt[i];
}
cout << cur;
}
cout << '\n';
}
}
Compilation message (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... |