Submission #2105854
Source Code Expand
#include "bits/stdc++.h" using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int INF = 1e9; const ll LINF = 1e18; /* <url:https://arc080.contest.atcoder.jp/tasks/arc080_b> 問題文============================================================ 縦 H 行、横 W 列のマス目があります。 すぬけ君は、このマス目を色 1, 2, …, N で塗り分けようとしています。 このとき、次の条件が成り立つようにします。 各 i (1≤i≤N) について、色 i のマスはちょうど ai 個存在する。 ただし、a1+a2+…+aN=HW である。 各 i (1≤i≤N) について、色 i のマスは上下左右に連結である。 すなわち、どの色 i のマスからどの色 i のマスへも、上下左右に隣り合う色 i のマスのみを辿って行き来できる。 条件を満たす塗り分け方をひとつ求めてください。 解は必ず存在することが示せます。 ================================================================= 解説============================================================= 蛇のようにマスをなぞりながら値を入れていけばok ================================================================ */ int main(void) { cin.tie(0); ios::sync_with_stdio(false); ll H,W; cin >> H >> W; ll N; cin >> N; vector<ll> a(N); for(auto& in:a) cin >> in; vector<vector<int>> masu(H+2,vector<int>(W+2,-1)); for(int i = 1; i <=H;i++) for(int j = 1; j<= W;j++) masu[i][j] = 0; int aidx = 0; for(int i = 1; i<= H;i++){ if(i%2 == 1){ for(int j = 1; j <= W;j++){ masu[i][j] = aidx+1; a[aidx]--; if(a[aidx] == 0) aidx++; } }else{ for(int j = W; j >= 1;j--){ masu[i][j] = aidx+1; a[aidx]--; if(a[aidx] == 0) aidx++; } } } for(int i = 1; i <= H; i++){ for(int j = 1; j <= W;j++){ cout << masu[i][j] << " "; } cout << endl; } return 0; }
Submission Info
Submission Time | |
---|---|
Task | D - Grid Coloring |
User | vjudge4 |
Language | C++14 (GCC 5.4.1) |
Score | 400 |
Code Size | 2164 Byte |
Status | AC |
Exec Time | 3 ms |
Memory | 384 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 400 / 400 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | 0_00.txt, 0_01.txt, 0_02.txt |
All | 0_00.txt, 0_01.txt, 0_02.txt, 1_00.txt, 1_01.txt, 1_02.txt, 1_03.txt, 1_04.txt, 1_05.txt, 1_06.txt, 1_07.txt, 1_08.txt, 1_09.txt, 1_10.txt, 1_11.txt, 1_12.txt, 1_13.txt, 1_14.txt, 1_15.txt, 1_16.txt, 1_17.txt, 1_18.txt, 1_19.txt, 1_20.txt, 1_21.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
0_00.txt | AC | 1 ms | 256 KB |
0_01.txt | AC | 1 ms | 256 KB |
0_02.txt | AC | 1 ms | 256 KB |
1_00.txt | AC | 1 ms | 256 KB |
1_01.txt | AC | 1 ms | 256 KB |
1_02.txt | AC | 1 ms | 256 KB |
1_03.txt | AC | 2 ms | 384 KB |
1_04.txt | AC | 2 ms | 384 KB |
1_05.txt | AC | 3 ms | 384 KB |
1_06.txt | AC | 2 ms | 256 KB |
1_07.txt | AC | 1 ms | 256 KB |
1_08.txt | AC | 1 ms | 256 KB |
1_09.txt | AC | 1 ms | 256 KB |
1_10.txt | AC | 1 ms | 256 KB |
1_11.txt | AC | 1 ms | 256 KB |
1_12.txt | AC | 1 ms | 256 KB |
1_13.txt | AC | 3 ms | 384 KB |
1_14.txt | AC | 1 ms | 256 KB |
1_15.txt | AC | 1 ms | 256 KB |
1_16.txt | AC | 1 ms | 256 KB |
1_17.txt | AC | 2 ms | 256 KB |
1_18.txt | AC | 1 ms | 256 KB |
1_19.txt | AC | 1 ms | 256 KB |
1_20.txt | AC | 1 ms | 256 KB |
1_21.txt | AC | 1 ms | 256 KB |