# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
870402 | 2023-11-07T17:26:32 Z | MercubytheFirst | Baloni (COCI15_baloni) | C++17 | 802 ms | 96092 KB |
#include<iostream> #include<vector> #include<iomanip> #include<algorithm> #include<map> #include<set> #include<climits> #include<numeric> #include<queue> #include<unordered_map> #include<string> #include<climits> #include<unordered_set> #include<bitset> #include<cstring> #include<cmath> #include<stack> #include<tuple> #include<complex> #if 1 #define pb push_back #define endl '\n' #define fi first #define se second #define fio ios_base::sync_with_stdio(false);cin.tie(NULL); #define CDIV(a,b) (((a)+(b)-(1))/(b)) using namespace std; using ll = long long; using ld = long double; const int inf = 10; const ll mod = 998244353; const ll N = 1e6+4; const ld PI = acos((ld)-1); #endif void fileio(string s = "test"){ #ifndef ONLINE_JUDGE freopen((s+string(".in")).c_str(),"r",stdin); freopen((s+string(".out")).c_str(),"w",stdout); #endif } ll bpow(ll a, ll p) { if(a == 0 or a == 1)return a; ll ans = 1; while(p) { if(p&1)ans = ans * a % mod; a = a * a % mod; p >>= 1; } return ans; } ll add(ll a, ll b){ if(a + b >= mod) return a + b - mod; return a + b; } ll sub(ll a, ll b){ if(a - b >= 0) return a - b; return a - b + mod; } ll mul(ll a, ll b){ return (a%mod)*(b%mod)%mod; } inline void solve() { int n; cin >> n; set<int> keep[N]; vector<int> v(n + 1, -1); for(int i = 1; i <= n; ++i){ cin >> v[i]; keep[v[i]].insert(i); } int ans = 0; for(int i = 1; i <= n; ++i){ if(v[i] == -1) continue; ans++; // cout << i << ' '; int cur = v[i], lasti = i; while(cur >= 1 and !keep[cur].empty()){ auto it = keep[cur].lower_bound(lasti); if(it == keep[cur].end()) break; v[*it] = -1; lasti = *it; keep[cur].erase(it); cur--; } } cout << ans << endl; } signed main(){ // fileio(); fio; //int t;cin >> t;while(t-->0) solve(); } /* */
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 32 ms | 47452 KB | Output is correct |
2 | Correct | 30 ms | 47664 KB | Output is correct |
3 | Correct | 31 ms | 47416 KB | Output is correct |
4 | Correct | 31 ms | 47448 KB | Output is correct |
5 | Correct | 688 ms | 91064 KB | Output is correct |
6 | Correct | 802 ms | 96092 KB | Output is correct |
7 | Correct | 583 ms | 87352 KB | Output is correct |
8 | Correct | 570 ms | 86868 KB | Output is correct |
9 | Correct | 615 ms | 89180 KB | Output is correct |
10 | Correct | 614 ms | 90688 KB | Output is correct |