提出 #1560005


ソースコード 拡げる

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<iostream>
#include<queue>
#include<map>
#include<cmath>
#include<set>
#include<stack>
#define ll long long
#define pb push_back
#define max(x,y) ((x)>(y)?(x):(y))
#define min(x,y) ((x)>(y)?(y):(x))
#define cls(name,x) memset(name,x,sizeof(name))
#define fs first
#define sc second
#define mp make_pair
#define L(x) (1<<x)
#define next Next
using namespace std;
const int inf=1e9+10;
const ll llinf=1e16+10;
const int maxn=1e5+10;
const int maxm=1e3+10;
const int mod=1e9+7;
int n;
int A[maxn];
int main()
{
    //freopen("in.txt","r",stdin);
    while(~scanf("%d",&n))
    {
        for(int i=1;i<=n;i++)
            scanf("%d",&A[i]);
        int ans=0;
        for(int i=1;i<=n;i++)
        {
            if(A[i]==i)
            {
                if(i<=n-1 && A[i+1]!=i)
                    swap(A[i],A[i+1]);
                else if(i>=1 && A[i-1]!=i)
                    swap(A[i],A[i-1]);
                ans++;
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}

提出情報

提出日時
問題 D - Derangement
ユーザ jxnu_mgz
言語 C++14 (GCC 5.4.1)
得点 400
コード長 1142 Byte
結果 AC
実行時間 11 ms
メモリ 640 KiB

コンパイルエラー

./Main.cpp: In function ‘int main()’:
./Main.cpp:36:30: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d",&A[i]);
                              ^

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 400 / 400
結果
AC × 4
AC × 15
セット名 テストケース
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
ケース名 結果 実行時間 メモリ
0_000.txt AC 1 ms 256 KiB
0_001.txt AC 1 ms 256 KiB
0_002.txt AC 1 ms 256 KiB
0_003.txt AC 1 ms 256 KiB
1_004.txt AC 1 ms 256 KiB
1_005.txt AC 10 ms 640 KiB
1_006.txt AC 10 ms 640 KiB
1_007.txt AC 10 ms 640 KiB
1_008.txt AC 10 ms 640 KiB
1_009.txt AC 10 ms 640 KiB
1_010.txt AC 10 ms 640 KiB
1_011.txt AC 10 ms 640 KiB
1_012.txt AC 10 ms 640 KiB
1_013.txt AC 11 ms 640 KiB
1_014.txt AC 10 ms 640 KiB