답안 #171670

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
171670 2019-12-29T22:03:51 Z Tuk1352 Jetpack (COCI16_jetpack) C++11
80 / 80
124 ms 10500 KB
#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    cin >> n;
    char C[10][n];
    int D[10][n+1], P[10][n+1], I, Y=n-1;
    for (int i = 0; i < 10; i++)
    {
        for (int y = 0; y < n; y++)
        {
            cin >> C[i][y];
            P[i][y] = 0;
        }
    }
    for (int i = 0; i < 10; i++)
    {
        D[i][0] = 0;
    }
    D[9][0] = 1;
    for (int y = 1; y < n; y++)
    {
        for (int i = 0; i < 10; i++)
        {
            D[i][y] = 0;
            if (C[i][y] != 'X')
            {
                if (i == 9)
                {
                    if (D[i][y-1] == 1)
                    {
                        D[i][y] = 1;
                    }
                    else if (D[i-1][y-1] == 1)
                    {
                        D[i][y] = 1;
                        P[i][y] = -1;
                    }
                }
                else if (i == 0)
                {
                    if (D[i][y-1] == 1)
                    {
                        D[i][y] = 1;
                    }
                    else if (D[i+1][y-1] == 1)
                    {
                        D[i][y] = 1;
                        P[i][y] = 1;
                    }
                }
                else
                {
                    if (D[i-1][y-1] == 1)
                    {
                        P[i][y] = -1;
                        D[i][y] = 1;
                    }
                    else if (D[i+1][y-1] == 1)
                    {
                        P[i][y] = 1;
                        D[i][y] = 1;
                    }
                }
            }
        }
    }
    for (int i = 0; i < 9; i++)
    {
        if (D[i][n-1] == 1)
        {
            I = i;
        }
    }
    vector <pair<int,int>> V;
    int k = 0;
    while (Y != -1)
    {
        if (P[I][Y] == 1 || (P[I][Y] == 0 && I == 0))
        {
            k++;
        }
        else if (k != 0)
        {
            V.push_back({Y,k});
            k = 0;
        }
        I += P[I][Y];
        Y--;
    }
    cout << V.size() << "\n";
    for (int i = V.size()-1; i >= 0; i--)
    {
        cout << V[i].first << " " << V[i].second << "\n";
    }
    return 0;
}

Compilation message

jetpack.cpp: In function 'int main()':
jetpack.cpp:82:43: warning: 'I' may be used uninitialized in this function [-Wmaybe-uninitialized]
         if (P[I][Y] == 1 || (P[I][Y] == 0 && I == 0))
                             ~~~~~~~~~~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 372 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 7 ms 760 KB Output is correct
6 Correct 9 ms 888 KB Output is correct
7 Correct 24 ms 2296 KB Output is correct
8 Correct 57 ms 5132 KB Output is correct
9 Correct 87 ms 7544 KB Output is correct
10 Correct 124 ms 10500 KB Output is correct