Submission #1561673
Source Code Expand
#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 Info
Submission Time | |
---|---|
Task | D - Derangement |
User | Nafmo2 |
Language | C++14 (GCC 5.4.1) |
Score | 400 |
Code Size | 1551 Byte |
Status | AC |
Exec Time | 10 ms |
Memory | 640 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 400 / 400 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | 0_000.txt, 0_001.txt, 0_002.txt, 0_003.txt |
All | 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 |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
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 |