제출 #1329546

#제출 시각아이디문제언어결과실행 시간메모리
1329546adscodingDango Maker (JOI18_dango_maker)C++20
0 / 100
0 ms344 KiB
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define FOR(i, a, b) for (int i = a, _b = b; i <= _b; ++i)
#define FORD(i, a, b) for (int i = a, _b = b; i >= _b; --i)
#define FORLL(i, a, b) for (ll i = a, _b = b; i <= _b; ++i)
#define FORDLL(i, a, b) for (ll i = a, _b = b; i >= _b; --i)
#define all(x) x.begin(), x.end()
#define uni(x) sort(all(x)), x.erase(unique(all(x)), x.end())
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define dbg(...) debug(#__VA_ARGS__, __VA_ARGS__)

template<typename T>
void __print_one(const char *&s, const T &x)
{
    while (*s == ' ') ++s;
    const char *p = s;
    int bal = 0;
    while (*s)
    {
        if (*s == '(') ++bal;
        else if (*s == ')') --bal;
        else if (*s == ',' && bal == 0) break;
        ++s;
    }
    cerr.write(p, s - p) << " = " << x;
    if (*s == ',')
    {
        ++s;
        cerr << "  ,  ";
    }
}

template<typename... Args>
void debug(const char *s, Args... args)
{
    cerr << "[  ";
    int dummy[] = { 0 , ( __print_one(s, args) , 0 )... };
    (void)dummy;
    cerr << "  ]\n\n";
}

template<class X>
bool maximize(X &a, X b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}

template<class X>
bool minimize(X &a, X b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}

// --------------------------------------------------------------------------------------------

const int maxn = 3003;
int n, m, dp[maxn][3];
char dango[maxn][maxn];

// --------------------------------------------------------------------------------------------

bool valid(int x, int y)
{
    return x >= 1 && x <= n && y >= 1 && y <= m;
}

bool checkNgang(int x, int y)
{
    if (!valid(x, y) || !valid(x, y + 1) || !valid(x, y + 2)) return false;
    if (dango[x][y] != 'R' || dango[x][y + 1] != 'G' || dango[x][y + 2] != 'W') return false;
    return true;
}

bool checkDoc(int x, int y)
{
    if (!valid(x, y) || !valid(x + 1, y) || !valid(x + 2, y)) return false;
    if (dango[x][y] != 'R' || dango[x + 1][y] != 'G' || dango[x + 2][y] != 'W') return false;
    return true;
}

ll calc(int x, int y)
{
    dp[y - 1][0] = 0;
    dp[y - 1][1] = -1e9;
    dp[y - 1][2] = -1e9;

    int sta = y;

    while (valid(x, y))
    {
        dp[y][0] = max({dp[y - 1][0], dp[y - 1][1], dp[y - 1][2]});
        if (checkNgang(x, y)) dp[y][1] = max({dp[y - 1][0], dp[y - 1][1], dp[y - 1][2]}) + 1;
        if (checkDoc(x, y))
        {
            dp[y][2] = dp[y - 1][2] + 1;
            if (y - 2 >= 0)
                dp[y][2] = max(dp[y][2], max(dp[y - 2][0], dp[y - 2][2]) + 1);
        }
        --x;
        ++y;
    }
    int res = max({dp[y - 1][0], dp[y - 1][1], dp[y - 1][2]});
    FOR(i, sta, y)
        FOR(j, 0, 2)
            dp[i][j] = -1e9;
    return res;
}

void solve()
{
    cin >> n >> m;
    FOR(i, 1, n)
        FOR(j, 1, m)
            cin >> dango[i][j];

    int res = 0;
    FOR(i, 1, n)
        res += calc(i, 1);
    FOR(i, 2, m)
        res += calc(n, i);

    cout << res;
}

signed main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    #define TASK "TEST"
    if (fopen(TASK".INP", "r"))
    {
        freopen(TASK".INP", "r", stdin);
        freopen(TASK".OUT", "w", stdout);
    }
    solve();
    return 0;
}

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

dango_maker.cpp: In function 'int main()':
dango_maker.cpp:148:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  148 |         freopen(TASK".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
dango_maker.cpp:149:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  149 |         freopen(TASK".OUT", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...