// Slower C++ solution:
/*9:00 UTC+4.5

Contest2 [Cloned]

End: 2019-09-02 13:00 UTC+4.5

04:00:00

Ended

Overview

Problem

Status

Rank (04:00:00)

0 Comments

Previous12345…Next

Username



Amirack

Prob

	Result 

	Time

(ms)	Mem

(MB)	Lang 

	Submit Time

Amirack

E

Wrong Answer

C++

6 days ago

Amirack

E

Language Rejected

C++

6 days ago

Amirack

B

Accepted

6	1.4	

C++

6 days ago

Amirack

B

Wrong Answer

C++

6 days ago

Amirack

A

Accepted

1	0.3	

C++

6 days ago

           

All Copyright Reserved © 2010-2019 Xu Han

Server Time: 2019-09-08 18:16:44 UTC+4.5



#21598412 | Amirack's solution for [AtCoder-2687] [Problem B]

Status

Accepted

Time

6ms

Memory

1408kB

Length

1046

Lang

C++14 (GCC 5.3.0)

Submitted

2019-09-02 10:16:44

Shared



RemoteRunId

7304502

25.0 / 25.0

Select Code

*/

#include <bits/stdc++.h>

using namespace std;

typedef  long long ll ;

const int maxn=1e2+3,maxxn=1e4+2;

vector<pair<int,int> >v[maxn][maxn];

bool mark[maxn][maxn];

int ans[maxn][maxn];

pair<int,int>p[maxxn];

int c;

void dfs(int u,int k){

    mark[u][k]=1;

    if(p[c].first<=0)c++;

    ans[u][k]=p[c].second;

    p[c].first--;

    for(int i=0;i<v[u][k].size();i++){

        int x1=v[u][k][i].first,y1=v[u][k][i].second;

        if(!mark[x1][y1])dfs(x1,y1);

    }

}

int main() {

    int h,w,n;

    cin>>h>>w>>n;

    for(int i=0;i<n;i++){

        int x;

        cin>>x;

        p[i]=make_pair(x,i+1);

    }

    for(int i=1;i<=h;i++){

        for(int j=1;j<=w;j++){

            if(j+1<=w)v[i][j].push_back(make_pair(i,j+1));

            if(j-1>0)v[i][j].push_back(make_pair(i,j-1));

            if(i+1<=h)v[i][j].push_back(make_pair(i+1,j));

            if(i-1>0)v[i][j].push_back(make_pair(i-1,j));

        }

    }

    dfs(1,1);

    for(int i=1;i<=h;i++){

        for(int j=1;j<=w;j++)cout<<ans[i][j]<<" ";

        cout<<endl;

    }

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.246326524817118x):
#include <bits/stdc++.h>

using namespace std;

#define x_ real()

#define y_ imag()

#define cross(a, b) (conj(a)*(b)).imag()

#define dot(a, b) (conj(a)*(b)).real()

#define PI acos(-1)

#define F first

#define S second

#define fastIO ios_base::sync_with_stdio(false), cin.tie(NULL)

#define fileIO freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)

#define ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>

typedef long double ld;

typedef long long ll;

typedef unsigned long long ull;

typedef complex<ld> point;

typedef tuple<int, int, int> line;

typedef vector<point> polygon;

typedef pair<double, double> pd;

pair<int, int> dirs[] = { {1, 2}, {-1, 2}, {2, 1}, {2, -1}, {-2, 1}, {-2, -1}, {1, -2}, {-1, -2} };







int main() {

	fastIO;

	int h, w, n, x;

	cin >> h >> w >> n;

	vector<int> v;

	for (int i = 0; i < n; i++) {

		cin >> x;

		v.push_back(x);

	}



	int grid[h][w];



	int curr = 0;

	for (int i = 0; i < h; i++) {

		if (i&1) {

			for (int j = w-1; j >= 0; j--) {

				grid[i][j] = curr+1;

				v[curr]--;

				if (v[curr] == 0)

					curr++;

			}

		}

		else {

			for (int j = 0; j < w; j++) {

				grid[i][j] = curr+1;

				v[curr]--;

				if (v[curr] == 0)

					curr++;

			}

		}

	}



	for (int i = 0; i < h; i++) {

		for (int j = 0; j < w; j++)

			cout << grid[i][j] << " ";

		cout << endl;

	}













}