結果

問題 No.1034 テスターのふっぴーさん
ユーザー marurunn11marurunn11
提出日時 2020-05-01 13:17:55
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 4,414 bytes
コンパイル時間 2,654 ms
コンパイル使用メモリ 211,316 KB
実行使用メモリ 814,568 KB
最終ジャッジ日時 2023-08-25 15:25:05
合計ジャッジ時間 5,195 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 79 ms
10,736 KB
testcase_11 AC 49 ms
10,560 KB
testcase_12 AC 47 ms
8,804 KB
testcase_13 AC 78 ms
10,184 KB
testcase_14 AC 51 ms
8,100 KB
testcase_15 AC 53 ms
10,356 KB
testcase_16 AC 31 ms
7,816 KB
testcase_17 AC 38 ms
10,356 KB
testcase_18 AC 78 ms
9,396 KB
testcase_19 AC 58 ms
9,464 KB
testcase_20 RE -
testcase_21 MLE -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _GLIBCXX_DEBUG
#include "bits/stdc++.h"
//#include <intrin.h>  //AtCoder (gcc) 上ではこれがあると動かない。__popcnt用のincludeファイル。
using namespace std;
using Graph = vector<vector<int>>;

typedef long long ll;
typedef long double ld;


#define int long long
#define rep(i, n) for(long long i = 0; i < (n); i++)
#define sqrt(d) pow((long double) (d), 0.50)

const int INF = 2e9;
const ll large_P = 1e9 + 7;



//繰り返し2乗法
//N^aの、Mで割った余りを求める。
ll my_pow(ll N, ll a, ll M) {
	ll tempo;
	if (a == 0) {
		return 1;
	}
	else {
		if (a % 2 == 0) {
			tempo = my_pow(N, a / 2, M);
			return (tempo * tempo) % M;
		}
		else {
			tempo = my_pow(N, a - 1, M);
			return (tempo * N) % M;
		}
	}
}



//N_C_a を M で割った余り
ll my_combination(ll N, ll a, ll M) {
	ll answer = 1;

	rep(i, a) {
		answer *= (N - i);
		answer %= M;
	}

	rep(i, a) {
		answer *= my_pow(i + 1, M - 2, M);
		answer %= M;
	}

	return answer;
}



ll my_gcd(ll& a, ll& b) {
	if (b == 0) return a;
	ll temp = a % b;
	return my_gcd(b, temp);
}



// long long型 n を、base 進法での、i 桁目の数が入った vector にする。
void ll_to_vector(ll base, ll n, vector<ll>& v) {
	ll tempo = n;

	ll n_digit = floor(log10(n) / log10(base)) + 1;
	v.assign(n_digit, 0);

	//ll n_digit = v.size();

	for (ll i = 0; i < n_digit; i++) {
		v.at(i) = tempo / pow(base, n_digit - 1 - i);
		tempo -= v.at(i) * pow(base, n_digit - 1 - i);
	}
}



int char_to_int(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2; case '3': return 3; case '4': return 4;
	case '5': return 5; case '6': return 6; case '7': return 7; case '8': return 8; case '9': return 9;
	default: return 0;
	}
}


//エラトステネスの篩で、prime で ないところに false を入れる。
//true で初期化された vector を代入する必要がある。
void prime_judge(vector<bool>& prime_or_not) {

	prime_or_not.at(0) = false;
	prime_or_not.at(1) = false;

	ll n = prime_or_not.size() - 1;
	ll region = sqrt(n) + 1;

	for (ll i = 2; i <= n / 2; i++) {
		prime_or_not.at(2 * i) = false;
	}


	for (ll i2 = 1; i2 < n / 2; i2++) {
		ll i = 2 * i2 + 1;  //ここからは奇数のみ探索
		if (i < region && prime_or_not.at(i)) {
			ll j = i * i;
			while (j < n + 1) {
				prime_or_not.at(j) = false;
				j += 2 * i;
			}
		}
	}
};



map<int, int> divide_to_prime(int target) {
	map<int, int> res;

	//sqrt(target) まで調べる。
	int upper_lim = ceil(sqrt(target));
	vector<bool> prime_or_not(upper_lim + 1, true);

	if (upper_lim < 20) prime_or_not.assign(25, true);
	prime_judge(prime_or_not);

	int tempo = target;
	rep(i, upper_lim + 1) {
		if (prime_or_not.at(i)) {
			while (tempo % i == 0) {
				tempo /= i;
				res[i]++;
			}
		}
	}
	
	if (tempo != 1) res[tempo]++; //sqrt(target) より大きな素因数は高々1つしかない。



	return res;
}






signed main() {
	int Q; cin >> Q;

	rep(i, Q) {
		int N; cin >> N;
		int I, J;
		cin >> I >> J;

		//int res = 0;

		//int w2 = N - 1 - w;
		//int h2 = N - 1 - h;

		//if (w >= h && (N - 1 - w) >= h && h < N / 2 + N % 2) {
			//res = 4 * (N - h) * h + (w - h);
		//}
		//else if (w >= h && (N - 1 - w) >= h && h < N / 2 + N % 2) {
		//
		//}

		vector<vector<int>> t(N, vector<int>(N, -1));
		
		int dw = 1, dh = 0;
		int w = 0, h = 0; t.at(h).at(w) = 0;

		while (true) {
			while (0 <= h + dh && h + dh <= N - 1 && 0 <= w + dw && w + dw <= N - 1 && t.at(h + dh).at(w + dw) == -1) {
				t.at(h + dh).at(w + dw) = t.at(h).at(w) + 1;
				w += dw;
				h += dh;
			}

			//if (t.at(I).at(J) != -1) break;

			if (dw == 1 && dh == 0 && 0 <= w + 0 && w + 0 <= N - 1 && 0 <= h + 1 && h + 1 <= N - 1 && t.at(h + 1).at(w + 0) == -1) {
				dw = 0; dh = 1;
			}
			else if (dw == 0 && dh == 1 && 0 <= w - 1 && w - 1 <= N - 1 && 0 <= h + 0 && h + 0 <= N - 1 && t.at(h + 0).at(w - 1) == -1) {
				dw = -1; dh = 0;
			}
			else if (dw == -1 && dh == 0 && 0 <= w - 0 && w - 0 <= N - 1 && 0 <= h - 1 && h - 1 <= N - 1 && t.at(h - 1).at(w - 0) == -1) {
				dw = 0; dh = -1;
			}
			else if (dw == 0 && dh == -1 && 0 <= w + 1 && w + 1 <= N - 1 && 0 <= h - 0 && h - 0 <= N - 1 && t.at(h + 0).at(w + 1) == -1) {
				dw = 1; dh = 0;
			}
			else break;
		}

		
		cout << t.at(I).at(J) << endl;

		//rep(i, N) {
			//rep(j, N) {
				//cout << t.at(i).at(j) << " ";
			//}
			//cout << endl;
		//}
	}
		

}
0