Submission #83652

# Submission time Handle Problem Language Result Execution time Memory
83652 2018-11-09T14:55:37 Z charlies_moo Spirale (COCI18_spirale) C++14
80 / 80
22 ms 636 KB
#include <fstream>
#include <iostream>
using namespace std;

int main()
{
    // initialize
    istream &fin = cin;
	ostream &fout = cout;
//    fin.open("spiral.in", ios::in);
//    fout.open("spiral.out", ios::out);
    
    // pretreatment
    int x = 49, y = 49, temp = 1;
    int cw[99][99] = {0};
    cw[49][49] = 1;
    for (int i = 0; i < 49; i++)
    {
        // up 1
        x--; cw[x][y] = ++temp;
        // right n+1
        for (int j = 0; j < 2 * i + 1; j++)
        {
            y++;
            cw[x][y] = ++temp;
        }
        // down n+2
        for (int j = 0; j < 2 * i + 2; j++)
        {
            x++;
            cw[x][y] = ++temp;
        }
        // left n+2
        for (int j = 0; j < 2 * i + 2; j++)
        {
            y--;
            cw[x][y] = ++temp;
        }
        // up n + 2
        for (int j = 0; j < 2 * i + 2; j++)
        {
            x--;
            cw[x][y] = ++temp;
        }
    }

    x = 49, y = 49, temp = 1;
    int ccw[99][99] = {0};
    ccw[49][49] = 1;
    for (int i = 0; i < 49; i++)
    {


        // up 1
        x--; ccw[x][y] = ++temp;
        // left n+1
        for (int j = 0; j < 2 * i + 1; j++)
        {
            y--;
            ccw[x][y] = ++temp;
        }
        // down n+2
        for (int j = 0; j < 2 * i + 2; j++)
        {
            x++;
            ccw[x][y] = ++temp;
        }
        // right n+2
        for (int j = 0; j < 2 * i + 2; j++)
        {
            y++;
            ccw[x][y] = ++temp;
        }
        // up n + 2
        for (int j = 0; j < 2 * i + 2; j++)
        {
            x--;
            ccw[x][y] = ++temp;
        }
    }

    int n, m, k;
    fin >> n >> m >> k;
    int sx[k];
    int sy[k];
    int t[k];
    for (int i = 0; i < k; i++)
    {
        int a, b;
        fin >> a >> b >> t[i];
        sx[i] = a-1;
        sy[i] = b-1;
    }

    // process
    int out[n][m];
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            int mini = 100000;
            for (int l = 0; l < k; l++)
            {
                if (t[l] == 0)
                {
                    int temp = cw[i - sx[l] + 49][j - sy[l] + 49];
                    if (temp < mini)
                        mini = temp;
                }
                else
                {
                    int temp =  ccw[i - sx[l] + 49][j - sy[l] + 49];
                    if (temp < mini)
                        mini = temp;
                }
            }
            fout << mini << " ";
        }
        fout << endl;
    }

    // debug
//    for (int i = 0; i < 99; i++)
//    {
//        for (int j = 0; j < 99; j++)
//        {
//            cout << cw[i][j] << "   ";
//        }
//        cout << endl;
//    }
}

Compilation message

spirale.cpp: In function 'int main()':
spirale.cpp:96:9: warning: unused variable 'out' [-Wunused-variable]
     int out[n][m];
         ^~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 504 KB Output is correct
4 Correct 2 ms 548 KB Output is correct
5 Correct 3 ms 548 KB Output is correct
6 Correct 2 ms 548 KB Output is correct
7 Correct 3 ms 636 KB Output is correct
8 Correct 2 ms 636 KB Output is correct
9 Correct 22 ms 636 KB Output is correct
10 Correct 2 ms 636 KB Output is correct