답안 #49828

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
49828 2018-06-03T11:37:54 Z A_H_Ghaznavi Spirale (COCI18_spirale) C++14
64 / 80
215 ms 764 KB
// In the name of god
// A.H.Ghaznavi
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=60;
int m,n,k,x,y,t,l,c,table[maxn][maxn],d,tab;
char rec[5];
void doing (char ch,int in)
{
    if (ch=='U')
    {
        for (int i=1;i<=in;i++)
        {
            if (l-i>=1 && (table[l-i][c]==-1 || tab<table[l-i][c]) && l-i<=n && c>=1  && c<=m)
                table[l-i][c]=tab;
            tab++;
        }
        l-=in;
    }
    if (ch=='D')
    {
        for (int i=1;i<=in;i++)
        {
            if (l+i<=n && (table[l+i][c]==-1 || tab<table[l+i][c]) && c>=1  && c<=m && l+i>=1)
                table[l+i][c]=tab;
            tab++;
        }
        l+=in;
    }
    if (ch=='L')
    {
        for (int i=1;i<=in;i++)
        {
            if (c-i>=1 && (table[l][c-i]==-1 || tab<table[l][c-i]) && l>=1 && l<=n && c-i<=m)
                table[l][c-i]=tab;
            tab++;
        }
        c-=in;
    }
    if (ch=='R')
    {
        for (int i=1;i<=in;i++)
        {
            if (c+i<=m && (table[l][c+i]==-1 || tab<table[l][c+i]) && l>=1 && l<=n && c+i>=1)
                table[l][c+i]=tab;
            tab++;
        }
        c+=in;
    }
}
int main()
{
    for (int i=0;i<maxn;i++)
    {
        for (int i2=0;i2<maxn;i2++)
            table[i][i2]=-1;
    }
    cin>>n>>m>>k;
    for (int i=0;i<k;i++)
    {
        cin>>x>>y>>t;
        l=x;
        c=y;
        if (t==0)
        {
            rec[0]='U';
            rec[1]='R';
            rec[2]='D';
            rec[3]='L';
        }
        if (t==1)
        {
            rec[0]='U';
            rec[1]='L';
            rec[2]='D';
            rec[3]='R';
        }
        d=0;
        tab=2;
        table[x][y]=1;
        for (int i=0;i<100;i++)
        {
            for (int i2=0;i2<4;i2++)
            {
                if (i2==0 || i2==2)
                    d++;
                doing(rec[i2],d);
            }
        }
    }
    for (int i=1;i<=n;i++)
    {
        for (int i2=1;i2<=m;i2++)
            cout<<table[i][i2]<<" ";
        cout<<endl;
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 360 KB Output is correct
3 Correct 2 ms 416 KB Output is correct
4 Correct 2 ms 420 KB Output is correct
5 Correct 2 ms 476 KB Output is correct
6 Runtime error 3 ms 608 KB Execution killed with signal 11 (could be triggered by violating memory limits)
7 Correct 3 ms 628 KB Output is correct
8 Correct 2 ms 632 KB Output is correct
9 Runtime error 215 ms 760 KB Execution killed with signal 11 (could be triggered by violating memory limits)
10 Correct 4 ms 764 KB Output is correct