// 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.2892146686764767x):
#include <iostream>

#include <cstdio>



using namespace std;



int ans[10005];

int res[105][105];



int main(){

    int h,w;

    scanf("%d %d",&h,&w);

    int n;

    scanf("%d",&n);

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

        scanf("%d",&ans[i]);

    }

    int k = 1;

    int l = 0;

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

        if (l == 0){

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

                if (ans[k]!=0){

                    res[j][i] = k;

                    ans[k]--;

                }

                else{

                    k++;

                    res[j][i] = k;

                    ans[k]--;

                }

            }

            l = 1;

        }

        else{

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

                if (ans[k]!=0){

                    res[j][i] = k;

                    ans[k]--;

                }

                else{

                    k++;

                    res[j][i] = k;

                    ans[k]--;

                }

            }

            l = 0;

        }

    }

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

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

            printf("%d%c",res[i][j],j == w-1?'\n':' ');

        }

    }

    return 0;



}