結果

問題 No.1438 Broken Drawers
ユーザー NOSSNOSS
提出日時 2021-03-26 21:26:42
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 24 ms / 2,000 ms
コード長 1,406 bytes
コンパイル時間 2,025 ms
コンパイル使用メモリ 202,700 KB
実行使用メモリ 4,792 KB
最終ジャッジ日時 2023-08-19 07:02:35
合計ジャッジ時間 3,861 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 20 ms
4,640 KB
testcase_07 AC 20 ms
4,700 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 9 ms
4,376 KB
testcase_13 AC 14 ms
4,376 KB
testcase_14 AC 7 ms
4,380 KB
testcase_15 AC 23 ms
4,696 KB
testcase_16 AC 21 ms
4,376 KB
testcase_17 AC 22 ms
4,696 KB
testcase_18 AC 22 ms
4,792 KB
testcase_19 AC 24 ms
4,688 KB
testcase_20 AC 23 ms
4,564 KB
testcase_21 AC 22 ms
4,688 KB
testcase_22 AC 23 ms
4,720 KB
testcase_23 AC 24 ms
4,696 KB
testcase_24 AC 24 ms
4,560 KB
testcase_25 AC 23 ms
4,696 KB
testcase_26 AC 23 ms
4,572 KB
testcase_27 AC 23 ms
4,684 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using P = pair<int, int>;
using P3 = pair<int,P>;
using PP = pair<P, P>;
constexpr int INF32 = 1 << 30;
constexpr ll INF64 = 1LL << 62;
// constexpr ll MOD = 1000000007;
constexpr ll MOD = 998244353;
constexpr int di[] = {0, 1, 0, -1};
constexpr int dj[] = {1, 0, -1, 0};
constexpr int di8[] = {0, 1, 1, 1, 0, -1, -1, -1};
constexpr int dj8[] = {1, 1, 0, -1, -1, -1, 0, 1};
constexpr double EPS = 1e-10;
const double PI = acos(-1);

#define ALL(v) (v).begin(),(v).end()
#define REP(i,n) for(int i=0,i_len=n; i<i_len; ++i)

template<typename T1,typename T2> bool chmax(T1 &a, T2 b) { if (a<b) { a=b; return 1; } return 0; }
template<typename T1,typename T2> bool chmin(T1 &a, T2 b) { if (b<a) { a=b; return 1; } return 0; }

int solve(){
    int n;
    cin >> n;
    vector<int> a(n), pos(n);
    vector<bool> used(n);
    REP(i,n){
        cin >> a[i];
        a[i]--;
        pos[a[i]] = i;
    }
    int ans = 0;
    REP(i,n){
        if(!used[i]){
            ans++;
            used[i] = true;
            if(pos[i]>0) used[a[pos[i]-1]] = true;
        }
    }
    cout << ans << endl;
    return 0;
}

int main(){
    cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);
    // int t; cin >> t; for(int i=0;i<t;i++) solve();
    // while(!solve());
    solve();
    return 0;
}
0