COFO::1459B Move and Turn

Problem

Point

Design

Complexity

Code

#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
#define rep(i, a, b) for(int i=(a); i<(b); i++)
using namespace std;

int n;
unsigned long long ans[1001];
void solve(){
    cin >> n;
    ans[1] = 4, ans[2] = 4, ans[3] = 12, ans[4] = 9;
    unsigned long long cur = 4;
    rep(i, 5, n+1){
        if(i%2 == 0){
            ans[i] = cur * cur;
            cur++;
        }else ans[i] = ans[i-1] * 4 - ans[i-2];
    }
    cout << ans[n] << '\n';
}
int main(){
    //freopen("input.txt", "r", stdin);
    solve();
    return 0;
}