結果
問題 | No.365 ジェンガソート |
ユーザー | hamray |
提出日時 | 2020-02-11 14:43:28 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 11 ms / 2,000 ms |
コード長 | 9,097 bytes |
コンパイル時間 | 1,336 ms |
コンパイル使用メモリ | 168,200 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-10-01 07:44:44 |
合計ジャッジ時間 | 2,782 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,820 KB |
testcase_01 | AC | 2 ms
6,816 KB |
testcase_02 | AC | 1 ms
6,820 KB |
testcase_03 | AC | 2 ms
6,816 KB |
testcase_04 | AC | 2 ms
6,820 KB |
testcase_05 | AC | 1 ms
6,816 KB |
testcase_06 | AC | 1 ms
6,816 KB |
testcase_07 | AC | 1 ms
6,816 KB |
testcase_08 | AC | 2 ms
6,820 KB |
testcase_09 | AC | 2 ms
6,816 KB |
testcase_10 | AC | 1 ms
6,820 KB |
testcase_11 | AC | 2 ms
6,816 KB |
testcase_12 | AC | 1 ms
6,816 KB |
testcase_13 | AC | 2 ms
6,816 KB |
testcase_14 | AC | 1 ms
6,816 KB |
testcase_15 | AC | 2 ms
6,816 KB |
testcase_16 | AC | 9 ms
6,820 KB |
testcase_17 | AC | 10 ms
6,816 KB |
testcase_18 | AC | 2 ms
6,820 KB |
testcase_19 | AC | 10 ms
6,816 KB |
testcase_20 | AC | 4 ms
6,816 KB |
testcase_21 | AC | 4 ms
6,816 KB |
testcase_22 | AC | 9 ms
6,816 KB |
testcase_23 | AC | 6 ms
6,820 KB |
testcase_24 | AC | 8 ms
6,816 KB |
testcase_25 | AC | 3 ms
6,820 KB |
testcase_26 | AC | 7 ms
6,820 KB |
testcase_27 | AC | 10 ms
6,820 KB |
testcase_28 | AC | 6 ms
6,820 KB |
testcase_29 | AC | 9 ms
6,820 KB |
testcase_30 | AC | 6 ms
6,820 KB |
testcase_31 | AC | 4 ms
6,816 KB |
testcase_32 | AC | 4 ms
6,816 KB |
testcase_33 | AC | 10 ms
6,816 KB |
testcase_34 | AC | 3 ms
6,820 KB |
testcase_35 | AC | 8 ms
6,816 KB |
testcase_36 | AC | 10 ms
6,816 KB |
testcase_37 | AC | 11 ms
6,816 KB |
testcase_38 | AC | 10 ms
6,820 KB |
testcase_39 | AC | 10 ms
6,820 KB |
testcase_40 | AC | 9 ms
6,820 KB |
ソースコード
#include <bits/stdc++.h> //typedef //-------------------------#include <bits/stdc++.h> #define M_PI 3.14159265358979323846 using namespace std; //conversion //------------------------------------------ inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; } template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); } inline int readInt() { int x; scanf("%d", &x); return x; } //typedef //------------------------------------------ typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<string> VS; typedef pair<int, int> PII; typedef pair<long long, long long> PLL; typedef pair<int, PII> TIII; typedef long long LL; typedef unsigned long long ULL; typedef vector<LL> VLL; typedef vector<VLL> VVLL; //container util //------------------------------------------ #define ALL(a) (a).begin(),(a).end() #define RALL(a) (a).rbegin(), (a).rend() #define PB push_back #define MP make_pair #define SZ(a) int((a).size()) #define SQ(a) ((a)*(a)) #define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i) #define EXIST(s,e) ((s).find(e)!=(s).end()) #define SORT(c) sort((c).begin(),(c).end()) //repetition //------------------------------------------ #define FOR(i,s,n) for(int i=s;i<(int)n;++i) #define REP(i,n) FOR(i,0,n) #define MOD 1000000007 #define rep(i, a, b) for(int i = a; i < (b); ++i) #define trav(a, x) for(auto& a : x) #define all(x) x.begin(), x.end() #define sz(x) (int)(x).size() typedef long long ll; typedef pair<int, int> pii; typedef vector<int> vi; const double EPS = 1E-8; #define chmin(x,y) x=min(x,y) #define chmax(x,y) x=max(x,y) class UnionFind { public: vector <ll> par; vector <ll> siz; vector <ll> maxv; UnionFind(ll sz_): par(sz_), siz(sz_, 1LL) { for (ll i = 0; i < sz_; ++i) par[i] = i; } void init(ll sz_) { par.resize(sz_); siz.assign(sz_, 1LL); for (ll i = 0; i < sz_; ++i) par[i] = i; } ll root(ll x) { while (par[x] != x) { x = par[x] = par[par[x]]; } return x; } bool merge(ll x, ll y) { x = root(x); y = root(y); if (x == y) return false; if (siz[x] < siz[y]) swap(x, y); siz[x] += siz[y]; par[y] = x; return true; } bool issame(ll x, ll y) { return root(x) == root(y); } ll size(ll x) { return siz[root(x)]; } }; ll mod_pow(ll x, ll n, ll mod){ ll res = 1; while(n){ if(n&1) res = (res * x)%mod; res %= mod; x = x * x %mod; n >>= 1; } return res; } #define SIEVE_SIZE 5000000+10 bool sieve[SIEVE_SIZE]; void make_sieve(){ for(int i=0; i<SIEVE_SIZE; ++i) sieve[i] = true; sieve[0] = sieve[1] = false; for(int i=2; i*i<SIEVE_SIZE; ++i) if(sieve[i]) for(int j=2; i*j<SIEVE_SIZE; ++j) sieve[i*j] = false; } bool isprime(ll n){ if(n == 0 || n == 1) return false; for(ll i=2; i*i<=n; ++i) if(n%i==0) return false; return true; } const int MAX = 2000010; long long fac[MAX], finv[MAX], inv[MAX]; // テーブルを作る前処理 void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++){ fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } // 二項係数計算 long long COM(int n, int k){ if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } long long extGCD(long long a, long long b, long long &x, long long &y) { if (b == 0) { x = 1; y = 0; return a; } long long d = extGCD(b, a%b, y, x); y -= a/b * x; return d; } // 負の数にも対応した mod (a = -11 とかでも OK) inline long long mod(long long a, long long m) { return (a % m + m) % m; } // 逆元計算 (ここでは a と m が互いに素であることが必要) long long modinv(long long a, long long m) { long long x, y; extGCD(a, m, x, y); return mod(x, m); // 気持ち的には x % m だが、x が負かもしれないので } ll GCD(ll a, ll b){ if(b == 0) return a; return GCD(b, a%b); } struct LazySegmentTree { private: int n; vector<ll> node, lazy; public: LazySegmentTree(vector<ll> v) { int sz = (int)v.size(); n = 1; while(n < sz) n *= 2; node.resize(2*n-1); lazy.resize(2*n-1, 0); for(int i=0; i<sz; i++) node[i+n-1] = v[i]; for(int i=n-2; i>=0; i--) node[i] = node[i*2+1] + node[i*2+2]; } void eval(int k, int l, int r) { if(lazy[k] != 0) { node[k] += lazy[k]; if(r - l > 1) { lazy[2*k+1] += lazy[k] / 2; lazy[2*k+2] += lazy[k] / 2; } lazy[k] = 0; } } void add(int a, int b, ll x, int k=0, int l=0, int r=-1) { if(r < 0) r = n; eval(k, l, r); if(b <= l || r <= a) return; if(a <= l && r <= b) { lazy[k] += (r - l) * x; eval(k, l, r); } else { add(a, b, x, 2*k+1, l, (l+r)/2); add(a, b, x, 2*k+2, (l+r)/2, r); node[k] = node[2*k+1] + node[2*k+2]; } } ll getsum(int a, int b, int k=0, int l=0, int r=-1) { if(r < 0) r = n; eval(k, l, r); if(b <= l || r <= a) return 0; if(a <= l && r <= b) return node[k]; ll vl = getsum(a, b, 2*k+1, l, (l+r)/2); ll vr = getsum(a, b, 2*k+2, (l+r)/2, r); return vl + vr; } }; int const INF = INT_MAX; struct SegmentTree { private: int n; vector<int> node; public: SegmentTree(vector<int> v) { int sz = v.size(); n = 1; while(n < sz) n *= 2; node.resize(2*n-1, INF); for(int i=0; i<sz; i++) node[i+n-1] = v[i]; for(int i=n-2; i>=0; i--) node[i] = min(node[2*i+1], node[2*i+2]); } void update(int x, int val) { x += (n - 1); node[x] = val; while(x > 0) { x = (x - 1) / 2; node[x] = min(node[2*x+1], node[2*x+2]); } } int getmin(int a, int b, int k=0, int l=0, int r=-1) { if(r < 0) r = n; if(r <= a || b <= l) return INF; if(a <= l && r <= b) return node[k]; int vl = getmin(a, b, 2*k+1, l, (l+r)/2); int vr = getmin(a, b, 2*k+2, (l+r)/2, r); return min(vl, vr); } }; using Weight = int; using Flow = int; struct Edge { int src, dst; Weight weight; Flow cap; Edge() : src(0), dst(0), weight(0) {} Edge(int s, int d, Weight w) : src(s), dst(d), weight(w) {} }; using Edges = std::vector<Edge>; using Graph = std::vector<Edges>; using Array = std::vector<Weight>; using Matrix = std::vector<Array>; void add_edge(Graph &g, int a, int b, Weight w = 1) { g[a].emplace_back(a, b, w); g[b].emplace_back(b, a, w); } void add_arc(Graph &g, int a, int b, Weight w = 1) { g[a].emplace_back(a, b, w); } // template<typename T> class basic_stopwatch: T { // typedef typename T BaseTimer; // public: // explicit basic_stopwatch(bool start); // explicit basic_stopwatch(char const* activity = "Stopwatch", bool start = true); // basic_stopwatch(std::ostream& log, char const* activity = "Stopwatch", bool start = true); // basic_stopwatch(); // unsigned LapGet() const; // bool IsStarted() const; // unsigned Show(char const* event = "show"); // unsigned Start(char const* event_name = "start"); // unsigned Stop(char const* event_name = "stop"); // private: // char const* m_activity; // unsigned m_lap; // std::ostream& m_log; // }; // #include <chrono> // using namespace std::chrono; // class TimerBase { // public: // // タイマをクリアする // TimerBase(): m_start(system_clock::time_point::min()) {} // void Clear(){ // m_start = system_clock::time_point::min(); // } // bool IsStarted() const { // return (m_start.time_since_epoch() != system_clock::duration(0)); // } // void Start() { // m_start = system_clock::now(); // } // unsigned long GetMs(){ // if(IsStarted()) { // system_clock::duration diff; // diff = system_clock::now() - m_start; // return (unsigned)(duration_cast<milliseconds>(diff).const(); // } // return 0; // } // private: // system_clock::time_point m_start; // }; int main() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); int N; cin >> N; vector<int> v(N); REP(i,N) cin >> v[i]; int zure = 0; int ans = 0; for(int i=N-1; i>=0; --i){ if(v[i] == i+1+zure){ }else if(v[i] < i+1+zure){ ans++; zure++; } //cout << v[i] << " " << i+1+zure << endl; } cout << ans << endl; return 0; }