結果
| 問題 |
No.918 LISGRID
|
| コンテスト | |
| ユーザー |
theory_and_me
|
| 提出日時 | 2019-10-26 02:45:22 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 2,305 bytes |
| コンパイル時間 | 1,809 ms |
| コンパイル使用メモリ | 181,244 KB |
| 実行使用メモリ | 14,024 KB |
| 最終ジャッジ日時 | 2024-09-13 14:23:29 |
| 合計ジャッジ時間 | 8,106 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 26 RE * 10 |
ソースコード
#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 = 101010; // !! 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;
}
theory_and_me