# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
665886 |
2022-11-27T13:57:51 Z |
Astrayt |
Money (IZhO17_money) |
C++17 |
|
2 ms |
1996 KB |
//君の手を握ってしまったら
//孤独を知らないこの街には
//もう二度と帰ってくることはできないのでしょう
//君が手を差し伸べた 光で影が生まれる
//歌って聞かせて この話の続き
//連れて行って見たことない星まで
//さユリ - 花の塔
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
#define starburst ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pii pair<int,int>
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define maxn 100005
#define mod 1000000007
struct DisjointSetUnion{
int par[maxn];
void init(){
for(int i = 1; i <= maxn - 1; ++i) par[i] = i;
}
int qry(int u){
return (u == par[u] ? u : par[u] = qry(par[u]));
}
void uni(int u, int v){
u = qry(u), v = qry(v);
par[u] = v;
}
}dsu;
void solve(){
int n, ans = 0; cin >> n;
vector<int> v(n), cnt(maxn, 0);
for(auto &x:v) cin >> x, cnt[x]++;
dsu.init();
for(int i = maxn - 1; i >= 1; --i) if(cnt[i] == 0) dsu.uni(i, i - 1);
for(int i = n - 1, j = n - 1; i >= 0; i = j){
ans++;
while(j >= 0 && v[i] == v[j]) cnt[v[j]]--, j--;
if(cnt[v[i]] == 0) dsu.uni(v[i], v[i] - 1);
int x = dsu.qry(v[i] - 1);
while(j >= 0){
if(x != v[j]) break;
cnt[v[j]]--, j--;
if(cnt[x] == 0){
dsu.uni(x, x - 1);
x = dsu.qry(x);
}
}
}
cout << ans << '\n';
}
signed main(){
starburst
int t = 1; //cin >> t;
while(t--) solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1864 KB |
Output is correct |
2 |
Correct |
1 ms |
1876 KB |
Output is correct |
3 |
Correct |
1 ms |
1860 KB |
Output is correct |
4 |
Correct |
2 ms |
1868 KB |
Output is correct |
5 |
Correct |
2 ms |
1876 KB |
Output is correct |
6 |
Correct |
2 ms |
1876 KB |
Output is correct |
7 |
Runtime error |
2 ms |
1996 KB |
Execution killed with signal 11 |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1864 KB |
Output is correct |
2 |
Correct |
1 ms |
1876 KB |
Output is correct |
3 |
Correct |
1 ms |
1860 KB |
Output is correct |
4 |
Correct |
2 ms |
1868 KB |
Output is correct |
5 |
Correct |
2 ms |
1876 KB |
Output is correct |
6 |
Correct |
2 ms |
1876 KB |
Output is correct |
7 |
Runtime error |
2 ms |
1996 KB |
Execution killed with signal 11 |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1864 KB |
Output is correct |
2 |
Correct |
1 ms |
1876 KB |
Output is correct |
3 |
Correct |
1 ms |
1860 KB |
Output is correct |
4 |
Correct |
2 ms |
1868 KB |
Output is correct |
5 |
Correct |
2 ms |
1876 KB |
Output is correct |
6 |
Correct |
2 ms |
1876 KB |
Output is correct |
7 |
Runtime error |
2 ms |
1996 KB |
Execution killed with signal 11 |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1864 KB |
Output is correct |
2 |
Correct |
1 ms |
1876 KB |
Output is correct |
3 |
Correct |
1 ms |
1860 KB |
Output is correct |
4 |
Correct |
2 ms |
1868 KB |
Output is correct |
5 |
Correct |
2 ms |
1876 KB |
Output is correct |
6 |
Correct |
2 ms |
1876 KB |
Output is correct |
7 |
Runtime error |
2 ms |
1996 KB |
Execution killed with signal 11 |
8 |
Halted |
0 ms |
0 KB |
- |