結果
問題 | No.918 LISGRID |
ユーザー |
![]() |
提出日時 | 2019-10-26 02:46:48 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 46 ms / 2,000 ms |
コード長 | 2,305 bytes |
コンパイル時間 | 1,861 ms |
コンパイル使用メモリ | 180,464 KB |
実行使用メモリ | 14,552 KB |
最終ジャッジ日時 | 2024-09-13 14:24:45 |
合計ジャッジ時間 | 4,846 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 36 |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef unsigned long long ull; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<double, double> pdd; const ull mod = 1e9 + 7; #define REP(i,n) for(int i=0;i<(int)n;++i) //debug #define dump(x) cerr << #x << " = " << (x) << endl; #define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl; template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){ os << "(" << v.first << ", " << v.second << ")"; return os; } template<class T> ostream& operator << (ostream& os, const vector<T> v){ for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os; } template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){ for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os; } typedef vector<ll> Edges; typedef vector<Edges> Graph; const ll V_MAX = 160005; // !! SHOULD BE EDITTED !! vector<ll> ts(V_MAX, -1); bool topologicalSort(Graph &G){ ll V = G.size(); vector<ll> indeg(V, 0); queue<ll> qu; REP(i, V){ REP(j, G[i].size()){ indeg[G[i][j]]++; } } REP(i, V){ if(!indeg[i]) qu.push(i); } ll idx = 0; while(!qu.empty()){ ll s = qu.size(); REP(i, s){ ll now = qu.front();qu.pop(); ts[now] = idx; idx++; REP(j, G[now].size()){ ll next = G[now][j]; indeg[next]--; if(!indeg[next]) qu.push(next); } } } return (idx == V); } int main(){ cin.tie(0); ios::sync_with_stdio(false); ll H, W; cin >> H >> W; vector<ll> A(H), B(W); REP(i, H) cin >> A[i]; REP(j, W) cin >> B[j]; sort(A.begin(), A.end()); sort(B.begin(), B.end()); Graph G(H*W); REP(i, H){ REP(j, W-1){ if(j<A[i]-1) G[W*i+j].push_back(W*i+j+1); else G[W*i+j+1].push_back(W*i+j); } } REP(j, W){ REP(i, H-1){ if(i<B[j]-1) G[W*i+j].push_back(W*i+j+W); else G[W*i+j+W].push_back(W*i+j); } } topologicalSort(G); /* REP(i, H*W){ dump(i) REP(j, G[i].size()){ cout << G[i][j] << " "; } cout << endl; } */ REP(i, H){ REP(j, W){ cout << ts[W*i+j]+1 << " "; } cout << endl; } return 0; }