AtCoder Beginner Contest 025

Submission #3733349

Source codeソースコード

#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
using namespace std;
typedef long long Int;
typedef pair<Int,Int> P;
const Int inf=0xfffffffffff;
int grid[6][6]={0};
bool used[26]={0};
vector<P> nonused;
int main(){
  for(int i=0;i<5;i++){
    for(int j=0;j<5;j++){
      cin>>grid[i][j];
      used[grid[i][j]]=1;
      if(grid[i][j]==0) nonused.push_back(P(i,j));
    }
  }
  vector<int> num;
  for(int i=0;i<26;i++){
    if(used[i]==0) num.push_back(i);
  }
  Int ans=0;
  if(num.size()>0){
    do{
      int gr2[5][5];
      for(int i=0;i<5;i++){
        for(int j=0;j<5;j++) gr2[i][j]=grid[i][j];
      }
      for(int i=0;i<num.size();i++){
        gr2[nonused[i].first][nonused[i].second]=num[i];
      }
      bool f=true;
      for(int i=0;i<5;i++){
        for(int j=0;j<3;j++){
          if(gr2[i][j]>gr2[i][j+1]&&gr2[i][j+1]>gr2[i][j+2]) f=false;
          if(gr2[i][j]<gr2[i][j+1]&&gr2[i][j+1]<gr2[i][j+2]) f=false;
        }
      }
      for(int i=0;i<3;i++){
        for(int j=0;j<5;j++){
          if(gr2[i][j]>gr2[i+1][j]&&gr2[i+1][j]>gr2[i+2][j]) f=false;
          if(gr2[i][j]<gr2[i+1][j]&&gr2[i+1][j]<gr2[i+2][j]) f=false;
        }
      }
      if(f) ans++;
      ans%=1000000007;
    }while(next_permutation(num.begin(),num.end()));
  }
  else{
    bool f=true;
    int gr2[5][5];
    for(int i=0;i<5;i++){
      for(int j=0;j<5;j++) gr2[i][j]=grid[i][j];
    }
    for(int i=0;i<5;i++){
      for(int j=0;j<3;j++){
        if(gr2[i][j]>gr2[i][j+1]&&gr2[i][j+1]>gr2[i][j+2]) f=false;
        if(gr2[i][j]<gr2[i][j+1]&&gr2[i][j+1]<gr2[i][j+2]) f=false;
      }
    }
    for(int i=0;i<3;i++){
      for(int j=0;j<5;j++){
        if(gr2[i][j]>gr2[i+1][j]&&gr2[i+1][j]>gr2[i+2][j]) f=false;
        if(gr2[i][j]<gr2[i+1][j]&&gr2[i+1][j]<gr2[i+2][j]) f=false;
      }
    }
    if(f) ans=1;
  }
  cout<<ans<<endl;
}

Submission

Task問題 D - 25個の整数
User nameユーザ名 i7_yoc
Created time投稿日時
Language言語 C++14 (GCC 5.4.1)
Status状態 RE
Score得点 0
Source lengthソースコード長 1951 Byte
File nameファイル名
Exec time実行時間 ms
Memory usageメモリ使用量 -

Test case

Set

Set name Score得点 / Max score Cases
Sample - sample-01.txt,sample-02.txt,sample-03.txt,sample-04.txt
Subtask1 0 / 30 sample-01.txt,sample-02.txt,sample-03.txt,sample-04.txt,test-1-01.txt,test-1-02.txt,test-1-03.txt,test-1-04.txt,test-1-05.txt,test-1-06.txt,test-1-07.txt,test-1-08.txt,test-1-09.txt,test-1-10.txt,test-1-11.txt,test-1-12.txt,test-1-13.txt,test-1-14.txt,test-1-15.txt
Subtask2 0 / 70 sample-01.txt,sample-02.txt,sample-03.txt,sample-04.txt,test-1-01.txt,test-1-02.txt,test-1-03.txt,test-1-04.txt,test-1-05.txt,test-1-06.txt,test-1-07.txt,test-1-08.txt,test-1-09.txt,test-1-10.txt,test-1-11.txt,test-1-12.txt,test-1-13.txt,test-1-14.txt,test-1-15.txt,test-2-01.txt,test-2-02.txt,test-2-03.txt,test-2-04.txt,test-2-05.txt,test-2-06.txt,test-2-07.txt,test-2-08.txt,test-2-09.txt,test-2-10.txt

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
sample-01.txt AC 1 ms 256 KB
sample-02.txt AC 5 ms 256 KB
sample-03.txt AC 1 ms 256 KB
sample-04.txt RE
test-1-01.txt AC 5 ms 256 KB
test-1-02.txt AC 1 ms 256 KB
test-1-03.txt AC 1 ms 256 KB
test-1-04.txt AC 2 ms 256 KB
test-1-05.txt AC 2 ms 256 KB
test-1-06.txt AC 5 ms 256 KB
test-1-07.txt AC 5 ms 256 KB
test-1-08.txt AC 5 ms 256 KB
test-1-09.txt AC 5 ms 256 KB
test-1-10.txt RE
test-1-11.txt AC 1 ms 256 KB
test-1-12.txt AC 5 ms 256 KB
test-1-13.txt AC 1 ms 256 KB
test-1-14.txt AC 6 ms 256 KB
test-1-15.txt AC 5 ms 256 KB
test-2-01.txt TLE
test-2-02.txt TLE
test-2-03.txt TLE
test-2-04.txt TLE
test-2-05.txt TLE
test-2-06.txt TLE
test-2-07.txt TLE
test-2-08.txt TLE
test-2-09.txt TLE
test-2-10.txt TLE