結果
| 問題 | No.1500 Super Knight | 
| コンテスト | |
| ユーザー |  trineutron | 
| 提出日時 | 2021-05-07 23:23:21 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 34 ms / 2,000 ms | 
| コード長 | 1,914 bytes | 
| コンパイル時間 | 2,228 ms | 
| コンパイル使用メモリ | 205,368 KB | 
| 最終ジャッジ日時 | 2025-01-21 08:54:02 | 
| ジャッジサーバーID (参考情報) | judge2 / judge6 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 33 | 
ソースコード
#include <bits/stdc++.h>
#include <atcoder/modint>
using namespace std;
using namespace atcoder;
using mint = modint1000000007;
int main()
{
    int n;
    cin >> n;
    if (n < 10)
    {
        int ans = 0;
        vector<vector<bool>> table(6 * n + 1, vector<bool>(6 * n + 1));
        table.at(3 * n).at(3 * n) = true;
        const vector<int> dx{-3, -3, -3, -2, -2, 0, 0, 2, 2, 3, 3, 3};
        const vector<int> dy{-2, 0, 2, -3, 3, -3, 3, -3, 3, -2, 0, 2};
        for (int _ = 0; _ < n; _++)
        {
            vector<vector<bool>> newtable(6 * n + 1, vector<bool>(6 * n + 1));
            for (int i = 0; i <= 6 * n; i++)
            {
                for (int j = 0; j <= 6 * n; j++)
                {
                    if (not table.at(i).at(j))
                    {
                        continue;
                    }
                    for (int k = 0; k < 12; k++)
                    {
                        int newi = i + dx.at(k), newj = j + dy.at(k);
                        if (newi < 0 or 6 * n < newi or newj < 0 or 6 * n < newj)
                        {
                            continue;
                        }
                        newtable.at(newi).at(newj) = true;
                    }
                }
            }
            table = move(newtable);
        }
        for (int i = 0; i <= 6 * n; i++)
        {
            for (int j = 0; j <= 6 * n; j++)
            {
                if (table.at(i).at(j))
                {
                    ans++;
                }
            }
        }
        cout << ans << endl;
        return 0;
    }
    mint ans = mint(6) * n + 1;
    ans *= ans;
    if (n % 2)
    {
        ans--;
    }
    else
    {
        ans++;
    }
    ans /= 2;
    mint d = (n + 1) / 2;
    d *= 4 * d;
    if (n % 2)
    {
        d = mint(2) * n * (n + 1) - d;
    }
    ans -= d;
    cout << ans.val() << endl;
    return 0;
}
            
            
            
        