2019ICPC沈阳网络赛

A Maomao’s candy

这题在一小时的时候敲完,调了两个半小时,wawawa,然后被队友喂了k,然后都没做出来,(试图AK的选手)爆零了,还好队友给力。赛后,继续肉眼一小时,矩阵有负系数,没取正模。。。。。。。。。

#include
#include
#include
using namespace std;
#define ll long long
const ll mod = 1025436931;

struct mat {
	ll a[3][3];
	mat operator*(mat x) {
		mat ret = {};
		for (ll i = 0; i<3; i++) {
			for (ll j = 0; j<3; j++) {
				for (ll k = 0; k<3; k++) {
					ret.a[i][j] = (ret.a[i][j] + a[i][k] * x.a[k][j]) % mod;
				}
			}
		}
		return ret;
	}
};

ll mypow(ll b) {
	mat a = {0,0,-1,1,0,0,0,1,2 };
	mat ret = { 0,1,2,0,0,0,0,0,0 };
	while (b) {
		if (b & 1)ret = ret * a;
		a = a * a; b >>= 1;
	}
	return ret.a[0][0];
}

void calcu(ll n) {
	cout << (mypow(n - 1)+mod)%mod << endl;
}

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	//ll t;while(cin>>t)cout<
	ll n, m, r1, c1, r2, c2;
	ll t; cin >> t;
	while (t--) {
		cin >> n >> m >> r1 >> c1 >> r2 >> c2;
		if (r1 == r2 && c1 == c2) {
			cout << 1 << endl;
			continue;
		}
		if (n == 1 && m == 2 || n == 2 && m == 1) {
			cout << 1 << endl;
			continue;
		}
		ll dr = abs(r1 - r2), dc = abs(c1 - c2);
		ll pd = (dr + dc) % 2;
		if (pd == 1) {
			if (m == 1) {
				calcu(abs((r2>r1 ? n : 1) - r1) + 1);
				continue;
			}
			if (n == 1) {
				calcu(abs((c2>c1 ? m : 1) - c1) + 1);
				continue;
			}
			cout << "countless" << endl;
			continue;
		}
		if (dr == dc) {
			ll cc = c2>c1 ? m : 1;
			ll rr = r2>r1 ? n : 1;
			calcu(abs(cc - c1) + abs(rr - r1));
		}
		else {
			if (dr<dc)calcu((c2>c1 ? (m - c1) : c1 - 1) + max(n - r1, r1 - 1));
			else if (dc<dr)calcu((r2>r1 ? (n - r1) : r1 - 1) + max(m - c1, c1 - 1));
		}
	}
}

你可能感兴趣的:(2019ICPC沈阳网络赛)