제출 #1302396

#제출 시각아이디문제언어결과실행 시간메모리
1302396nhmktuJOI 문장 (JOI14_ho_t1)C++20
100 / 100
85 ms1420 KiB
#include <bits/stdc++.h>
#define ll long long
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define ROF(i,a,b) for(int i=a;i>=b;i--)
#define pi pair<int,int>
#define pii pair<int,pi>
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define sz(a) (int) a.size()
#define endl '\n'
#define data "data"

using namespace std;
const ll linf = 1e18;
const int inf = 1e9;
const int MOD = 1e9 + 7, N = 1e3;

void add(int &a, int b)
{
    a += b;
    if(a>=MOD)
        a-=MOD;
    if(a<0)
        a += MOD;
}

int modulo(int x)
{
    if(x<=1)
        return 1;
    return (MOD - MOD/x) * modulo(MOD/x) % MOD;
}

int mul(int a, int b)
{
    return (1ll *a%MOD * b%MOD) % MOD;
}

int n, m;
char c[N+3][N+3];
char t[3][3];

void inp(void)
{
    cin >> n >> m;
    FOR(i, 1, n) FOR(j, 1, m) cin >> c[i][j];
    FOR(i, 1, 2) FOR(j, 1, 2) cin >> t[i][j];
}

bool check(int i, int j)
{
    if(c[i-1][j-1] != t[1][1]) return 0;
    if(c[i-1][j] != t[1][2]) return 0;
    if(c[i][j-1] != t[2][1]) return 0;
    if(c[i][j] != t[2][2]) return 0;
    return 1;
}

int calc(int i, int j, char ch)
{
    int ret = 0;
    ret -= check(i, j);
    ret -= check(i, j + 1);
    ret -= check(i + 1, j);
    ret -= check(i + 1, j + 1);
    char pch = c[i][j];
    c[i][j] = ch;
    ret += check(i, j);
    ret += check(i, j + 1);
    ret += check(i + 1, j);
    ret += check(i + 1, j + 1);
    c[i][j] = pch;
    return ret;
}

void solve(void)
{
    int ans = 0;
    FOR(i, 1, n) FOR(j, 1, m) ans += check(i, j);
    int del = 0;
    FOR(i, 1, n)
    {
        FOR(j, 1, m)
        {
            del = max(del, calc(i, j, 'J'));
            del = max(del, calc(i, j, 'O'));
            del = max(del, calc(i, j, 'I'));
        }
    }
    cout << ans + del;
}

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    if(fopen(data".inp", "r"))
    {
        freopen(data".inp","r",stdin);
        freopen(data".out","w",stdout);
    }

    inp();
    solve();
    return 0;
}

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

2014_ho_t1.cpp: In function 'int main()':
2014_ho_t1.cpp:102:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  102 |         freopen(data".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
2014_ho_t1.cpp:103:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  103 |         freopen(data".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...