제출 #1329238

#제출 시각아이디문제언어결과실행 시간메모리
1329238adscodingDango 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 = 3e3 + 3;
int n, m;
char dango[maxn][maxn];

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

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

bool checkNgang(int x, int y)
{
    if (!validCell(x, y) || !validCell(x, y + 1) || !validCell(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 (!validCell(x, y) || !validCell(x + 1, y) || !validCell(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)
{
    ll dp_cur[3] = {0, ll(-1e18), ll(-1e18)};
    while (validCell(x, y))
    {
        ll dp_before[3];
        FOR(i, 0, 2)
            dp_before[i] = dp_cur[i];

        dp_cur[0] = max({dp_before[0], dp_before[1], dp_before[2]});
        if (checkNgang(x, y)) dp_cur[1] = max({dp_before[0], dp_before[1]}) + 1;
        if (checkDoc(x, y)) dp_cur[2] = max({dp_before[0], dp_before[2]}) + 1;

        --x;
        ++y;
    }

    return max({dp_cur[0], dp_cur[1], dp_cur[2]});
}

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

    ll 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:145:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  145 |         freopen(TASK".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
dango_maker.cpp:146:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  146 |         freopen(TASK".OUT", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...