LKNIGHT - Mã đi tuần
Tác giả: flashmt
Ngôn ngữ: C++
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
const int dx[]={-2,-1,1,2,2,1,-1,-2};
const int dy[]={1,2,2,1,-1,-2,-2,-1};
int main()
{
int n,k,x=0,y=0,maxx=0,maxy=0,minx=0,miny=0;
string s;
cin >> n >> k >> s;
for (int i=0;i<k;i++)
{
x+=dx[s[i]-'1']; y+=dy[s[i]-'1'];
maxx=max(maxx,x); minx=min(minx,x);
maxy=max(maxy,y); miny=min(miny,y);
}
cout << (n-maxx+minx)*(n-maxy+miny) << endl;
}