結果

問題 No.1169 Row and Column and Diagonal
ユーザー CyanmondCyanmond
提出日時 2020-08-14 22:34:24
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 20 ms / 2,000 ms
コード長 4,074 bytes
コンパイル時間 1,483 ms
コンパイル使用メモリ 125,836 KB
実行使用メモリ 5,504 KB
最終ジャッジ日時 2024-04-18 22:25:08
合計ジャッジ時間 2,227 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 3 ms
5,376 KB
testcase_07 AC 5 ms
5,376 KB
testcase_08 AC 7 ms
5,376 KB
testcase_09 AC 10 ms
5,376 KB
testcase_10 AC 16 ms
5,376 KB
testcase_11 AC 18 ms
5,504 KB
testcase_12 AC 17 ms
5,504 KB
testcase_13 AC 18 ms
5,504 KB
testcase_14 AC 20 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma region header
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>

// ===============================================================
//using系
#pragma region header
using namespace std;
using ll = long long;
using vl = vector<long long>;
using vvl = vector<vector<long long>>;
using vvi = vector<vector<int>>;
using Graph = vvi;
using vs = vector<string>;
using vc = vector<char>;
using vcc = vector<vector<char>>;
using vm = vector<short>;
using vmm = vector<vector<short>>;
using pii = pair<int, int>;
using psi = pair<string, int>;
using ld = long double;
using ull = unsigned long long;
using ui = unsigned int;
using qul = queue<ll>;
using pql = priority_queue<ll>;
using kaage = priority_queue<int, vector<int>, greater<int>>;
int dx[] = { 1,0,-1,0 };
int dy[] = { 0,1,0,-1 };
constexpr ll mod = 1e9 + 7;
#pragma endregion
// ========================================================================
//define系

//#define int long long
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i <= n; i++)

// ========================================================================

#pragma region header
ll gcd(ll a, ll b)
{
	if (a % b == 0)
	{
		return(b);
	}
	else
	{
		return(gcd(b, a % b));
	}
}
//最大公約数
ll lcm(ll a, ll b)
{
	return a * b / gcd(a, b);
}
//最小公倍数
ll box(double a)
{
	ll b = a;
	return b;
}
//切り捨て
ll fff(double a)
{
	ll b = a + 0.5;
	return b;
}
//四捨五入
ll mch(ll n) {
	if (n == 1) return 1;
	else return n * mch(n - 1);
}
//1から整数nまでの階乗を出す(INFで割っていない)
bool prime(ll a)//素数判定、primeならtrue,違うならfalse
{
	if (a < 2) return false;
	else if (a == 2) return true;
	else if (a % 2 == 0) return false;
	double m = sqrt(a);
	for (int i = 3; i <= m; i += 2)
	{
		if (a % i == 0)
		{
			return false;
		}
	}

	// 素数である
	return true;
}
//素数判定
ll modpow(ll a, ll n, ll mod) {
	ll hi = 1;
	while (n > 0) {
		if (n & 1) hi = hi * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return hi;
}
//いろいろやります(ただの前座)
ll mg(ll a, ll mod) {
	return modpow(a, mod - 2, mod);
}
//割り算の10^9+7等対策で逆元を出します 
#pragma endregion
#pragma endregion


// ========================================================================

#pragma region header
//ある程度のテンプレ(いじって使う)
//これとBFS、あとその時その時で使うものはここに書く
vector<bool> seens;
void dfs(const Graph& G, int v) {
	seens[v] = true; // v を訪問済にする

	// v から行ける各頂点 next_v について
	for (auto next_v : G[v]) {
		if (seens[next_v]) continue; // next_v が探索済だったらスルー
		dfs(G, next_v); // 再帰的に探索
	}
}



// ========================================================================
#pragma endregion

/*signed*/ int main() {
	ll n; cin >> n;
	vector<vector<ll>> d(n, vector<ll>(n));
	ll a = n / 2 + 1;
	for (ll i = 0; i < n; i++) {
		if (i % 2 == 0) {
			d[0][i] = i / 2 + 1;
		}
		else d[0][i] = a + (i / 2) + 1;
	}
	for (ll i = 1; i < n; i++) {
		if (i % 2 == 0) {
			d[i][n - 1] = a + (i / 2);
		}
		else {
			d[i][n - 1] = i / 2 + 1;
		}
	}
	for (int i = 1; i < n; i++) {
		for (int j = 0; j < n - 1; j++) {
			d[i][j] = d[i - 1][j + 1];
		}
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			cout << d[i][j];
			if (j != n - 1) {
				cout << ' ';
			}
			else cout << endl;
		}
	}

	return 0;
}
0