AtCoder Regular Contest 082

Submission #1561673

Source codeソースコード

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
typedef long long int ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<signed(n);i++)
#define EREP(i,n) for(int i=1;i<=signed(n);i++)
#define ALL(a) (a).begin(),(a).end()
using std::cout;
using std::vector;
using std::endl;
using std::cin;
using std::string;
//#define EVEL 1
#ifdef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const int MOD = 1000000007;
const ll INF = 50000000000000000;
typedef std::pair<int,int> P;
struct edge {int to,cost;};
    ll N;
    int A[100010];
    int C=0;
    ll ans=0;

int main(){
    std::ios_base::sync_with_stdio(false);
    cin>>N;
    REP(i,N)cin>>A[i];
    REP(i,N){
        DEB(i)DEB(A[i])DEB(A[i-1])DEB(A[i-2])
        if(A[i]==i+1){
            ans++;
            if(C==0)C++;
            else{
                if(i>0&&A[i-1]==i)C++;
                else C=1;
            }
            if(C%2==0&&C!=0)ans--;
            /*if(i>0&&A[i-1]==i){
                ans--;
                if(i>1&&A[i-2]==i-1){
                    ans++;
                }
            }*/
        }else C=0;
        DEB(ans)END
    }
    cout<<ans<<endl;
    return 0;
}

//ARC 082 D - Derangement

Submission

Task問題 D - Derangement
User nameユーザ名 Nafmo
Created time投稿日時
Language言語 C++14 (GCC 5.4.1)
Status状態 AC
Score得点 400
Source lengthソースコード長 1551 Byte
File nameファイル名
Exec time実行時間 10 ms
Memory usageメモリ使用量 640 KB

Test case

Set

Set name Score得点 / Max score Cases
Sample - 0_000.txt,0_001.txt,0_002.txt,0_003.txt
All 400 / 400 0_000.txt,0_001.txt,0_002.txt,0_003.txt,1_004.txt,1_005.txt,1_006.txt,1_007.txt,1_008.txt,1_009.txt,1_010.txt,1_011.txt,1_012.txt,1_013.txt,1_014.txt

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
0_000.txt AC 1 ms 256 KB
0_001.txt AC 1 ms 256 KB
0_002.txt AC 1 ms 256 KB
0_003.txt AC 1 ms 256 KB
1_004.txt AC 1 ms 256 KB
1_005.txt AC 9 ms 640 KB
1_006.txt AC 9 ms 640 KB
1_007.txt AC 9 ms 640 KB
1_008.txt AC 9 ms 640 KB
1_009.txt AC 9 ms 640 KB
1_010.txt AC 9 ms 640 KB
1_011.txt AC 9 ms 640 KB
1_012.txt AC 9 ms 640 KB
1_013.txt AC 10 ms 640 KB
1_014.txt AC 9 ms 640 KB