CSES - BAPC 2015 - Results
Submission details
Task:The King's Walk
Sender:Antti Röyskö
Submission time:2017-10-17 17:36:21 +0300
Language:C++
Status:READY
Result:
Test results
testverdicttime
#10.14 sdetails

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:30:9: warning: unused variable 'dd' [-Wunused-variable]
     int dd=dx-dy;
         ^

Code

#include <iostream>
using namespace std;
int T;

const int M=5318008;

int k[5050][5050];


int main(){
  k[0][0]=1;
  for (int i=1; i<5050; ++i){
    k[i][i]=1;
    k[i][0]=(k[i-1][0]+k[i-1][1]*2)%M;
    for (int j=1; j<i; ++j){
      k[i][j]=(k[i-1][j]+k[i-1][j-1])%M;
    }
  }
  
  cin >> T;
  for (int i=0; i<T; ++i){
    int N;
    cin >> N;
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    if (x2<x1) swap(x1, x2);
    if (y2<y1) swap(y1, y2);
    int dx=x2-x1;
    int dy=y2-y1;
    int dd=dx-dy;
    int dmn=min(dx, dy);
    int dmx=max(dx, dy);
    cout << k[dmx][dmn] << "\n";
  }
}

Test details

Test 1

Verdict:

input
100
315
152 73 251 114
3201
2894 304 697 2576
...

correct output
898608
4727344
240176
248812
1744064
...

user output
3985456
2244768
3540864
1948344
4159952
...