제출 #500487

#제출 시각아이디문제언어결과실행 시간메모리
500487IOI_champion_in_1980Red-blue table (IZhO19_stones)C++14
100 / 100
48 ms2280 KiB
// red blue izho 19
#include <iostream>
using namespace std;
const int maxN = 1005;
bool marked[maxN][maxN];
int num[maxN];
int solve(int n, int m)
{
    int midN = n / 2 + 1;
    int midM = (m - 1) / 2;
    for (int i = 0; i <= n + 1; i++)
    {
        for (int j = 0; j <= n + 1; j++)
        {
            marked[i][j] = 0;
        }
    }
    for (int i = 0; i <= n + 1; i++)
    {
        num[i] = 0;
    }
    int sum = n;
    int pointer = 1;
    for (int i = 1; i <= m; i++)
    {
        int steps;
        bool full = false;
        for (steps = 1; steps <= midN; steps++)
        {
            if (num[pointer] >= midM)
            {
                full = true;
                break;
            }
            marked[i][pointer] = true;
            num[pointer]++;
            pointer++;
            if (pointer > n)
            {
                pointer = 1;
            }
        }
        if (steps >= midN + 1)
        {
            sum++;
        }
        if(full)
        {
            break;
        }
    }
    cout << sum << endl;
    return 0;
}

void test(int n, int m)
{
    int sum = 0;
    if (n > m)
    {
        sum = solve(n, m);
        int place = 0;
        for (int i = 1; i <= n; i++)
        {
            for (int j = 1; j <= m; j++)
            {
                if (marked[j][i])
                {
                    cout << "-";
                }
                else
                {
                    cout << "+";
                }
            }
            cout << endl;
        }
    }
    else
    {
        sum = solve(m, n);
        for (int i = 1; i <= n; i++)
        {
            for (int j = 1; j <= m; j++)
            {
                if (marked[i][j])
                {
                    cout << "+";
                }
                else
                {
                    cout << "-";
                }
            }
           cout << endl;
        }
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin >> t;
    for (int i = 0; i < t; i++)
    {
        int n, m;
        cin >> n >> m;
        test(n, m);
    }
}

컴파일 시 표준 에러 (stderr) 메시지

stones.cpp: In function 'void test(int, int)':
stones.cpp:62:13: warning: unused variable 'place' [-Wunused-variable]
   62 |         int place = 0;
      |             ^~~~~
stones.cpp:58:9: warning: variable 'sum' set but not used [-Wunused-but-set-variable]
   58 |     int sum = 0;
      |         ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...