結果

問題 No.918 LISGRID
ユーザー ningenMeningenMe
提出日時 2019-05-26 03:38:35
言語 C++11
(gcc 11.4.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 4,219 bytes
コンパイル時間 1,173 ms
コンパイル使用メモリ 162,476 KB
最終ジャッジ日時 2024-04-27 02:52:32
合計ジャッジ時間 2,540 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
main.cpp:21:25: error: ‘make_v’ function uses ‘auto’ type specifier without trailing return type
   21 | template<typename... T> auto make_v(size_t N,T... t){return vector<decltype(make_v(t...))>(N,make_v(t...));}
      |                         ^~~~
main.cpp:21:25: note: deduced return type only available with ‘-std=c++14’ or ‘-std=gnu++14’

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;

#define REP(i,n) for(long long i = 0; i < (n); i++)
#define FOR(i, m, n) for(long long i = (m);i < (n); ++i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SPEED cin.tie(0);ios::sync_with_stdio(false);

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;

const ll MOD = (ll)1e9 + 7;
const ll MOD2 = 998244353;
const ll HIGHINF = (ll)1e18;
const ll LOWINF = (ll)1e15;
const long double PI = 3.1415926535897932384626433;

template<typename T> vector<T> make_v(size_t N,T init){return vector<T>(N,init);}
template<typename... T> auto make_v(size_t N,T... t){return vector<decltype(make_v(t...))>(N,make_v(t...));}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}
template <class T> void chmax(T& a, const T b){a=max<T>(a,b);}
template <class T> void chmin(T& a, const T b){a=min<T>(a,b);}
void YN(bool flg) {cout << ((flg) ? "YES" : "NO") << endl;}
void Yn(bool flg) {cout << ((flg) ? "Yes" : "No") << endl;}
void yn(bool flg) {cout << ((flg) ? "yes" : "no") << endl;}

int main() {

	//入力
	int N; cin >> N;
	V<int> a,b;
	
	for(int i = 1; i <= N; ++i){
		int tmp; cin >> tmp;
		assert(0 <= tmp && tmp <= N);
		for(int j = 0; j < tmp; ++j) a.push_back(i);
	}
	for(int i = 1; i <= N; ++i){
		int tmp; cin >> tmp;
		assert(0 <= tmp && tmp <= N);
		for(int j = 0; j < tmp; ++j) b.push_back(i);
	}
	assert(a.size()==N);
	assert(b.size()==N);

	//(i,j)からa[i],b[j]に対応した辺を張る
	vector<vector<int>> edge(N*N);//辺
	vector<vector<int>> cnt(N,vector<int>(N,0));//入次数
	for(int i = 0; i < N; ++i){
		for(int j = 0; j < N - a[i]; ++j){
			edge[i*N+j].push_back(i*N+j+1);
			cnt[i][j+1]++;
		}
		for(int j = N - a[i]; j + 1 < N; ++j){
			edge[i*N+j+1].push_back(i*N+j);
			cnt[i][j]++;
		}
	}
	for(int j = 0; j < N; ++j){
		for(int i = 0; i < N - b[j]; ++i){
			edge[i*N+j].push_back((i+1)*N+j);
			cnt[i+1][j]++;
		}
		for(int i = N - b[j]; i + 1 < N; ++i){
			edge[(i+1)*N+j].push_back(i*N+j);
			cnt[i][j]++;
		}
	}

	//出力する行列
	vector<vector<int>> ans(N,vector<int>(N,0));
	//4つ角からスタート
	vector<int> sy = {0,0,N-1,N-1},sx = {0,N-1,0,N-1};
	//デクリメントしていく値
	int val = N*N;

	//トポロジカル順を守りながらbfs;
	for(int i = 0; i < 4; ++i){
		queue<pair<int,int>> pq;
		if(!cnt[sy[i]][sx[i]]) pq.push({sy[i],sx[i]});
		while(pq.size()){
			int y = pq.front().first;
			int x = pq.front().second;
			pq.pop();
			ans[y][x] = val--;
			for(auto j: edge[y*N+x]){
				int s = j/N, t = j%N;
				cnt[s][t]--;
				if(!cnt[s][t]) pq.push({s,t});
			}
		}
	}
	
	for(int i = 0; i < N; ++i){
		for(int j = 0; j < N; ++j){
			cout << ans[i][j] << " ";
		}
		cout << endl;
	}
	return 0;
}
0