Submission #892152

# Submission time Handle Problem Language Result Execution time Memory
892152 2023-12-25T02:03:58 Z vkvkvkvk Bob (COCI14_bob) C++14
120 / 120
84 ms 8608 KB
#include <bits/stdc++.h>

#define int long long

#define file(task) if(fopen(task".inp", "r")) { freopen(task".inp", "r", stdin); freopen(task".out", "w", stdout); }
#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)

using namespace std;

const int maxN = 1e3;

int N, M;
int a[maxN+5][maxN+5];
int f[maxN+5], dp[maxN+5];

void read_input()
{
    cin >> N >> M;
    FOR(i, 1, N) FOR(j, 1, M) cin >> a[i][j];
}

void solve()
{
    stack<int> S;
    int ans = 0;
    FOR(i, 1, N)
    {
        while(!S.empty()) S.pop();
        int p = 0, id;
        FOR(j, 1, M)
        {
            if(a[i][j] != a[i - 1][j]) f[j] = 0; ++f[j];
            if(a[i][j] != a[i][j - 1])
            {
                p = j - 1;
                dp[j - 1] = 0;
                while(!S.empty()) S.pop();
            }
            while(!S.empty() && f[S.top()] >= f[j]) S.pop();
            if(S.empty()) id = p;
            else id = S.top();
//            cout << i << ' ' << j << ' ' << id << endl;
            dp[j] = dp[id] + (j - id) * f[j];
            S.push(j);
            ans += dp[j];
        }
    }
    cout << ans;
}

int32_t main()
{
    cin.tie(0)->sync_with_stdio(0);

    file("LAND");

    read_input();
    solve();

    return 0;
}

Compilation message

bob.cpp: In function 'void solve()':
bob.cpp:33:13: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   33 |             if(a[i][j] != a[i - 1][j]) f[j] = 0; ++f[j];
      |             ^~
bob.cpp:33:50: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   33 |             if(a[i][j] != a[i - 1][j]) f[j] = 0; ++f[j];
      |                                                  ^~
bob.cpp: In function 'int32_t main()':
bob.cpp:5:56: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | #define file(task) if(fopen(task".inp", "r")) { freopen(task".inp", "r", stdin); freopen(task".out", "w", stdout); }
      |                                                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
bob.cpp:56:5: note: in expansion of macro 'file'
   56 |     file("LAND");
      |     ^~~~
bob.cpp:5:89: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | #define file(task) if(fopen(task".inp", "r")) { freopen(task".inp", "r", stdin); freopen(task".out", "w", stdout); }
      |                                                                                  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
bob.cpp:56:5: note: in expansion of macro 'file'
   56 |     file("LAND");
      |     ^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 4696 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 4700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 4700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 4696 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 69 ms 8276 KB Output is correct
2 Correct 50 ms 8260 KB Output is correct
3 Correct 42 ms 8296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 83 ms 8272 KB Output is correct
2 Correct 43 ms 8284 KB Output is correct
3 Correct 41 ms 8272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 79 ms 8272 KB Output is correct
2 Correct 40 ms 8276 KB Output is correct
3 Correct 41 ms 8308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 84 ms 8608 KB Output is correct
2 Correct 42 ms 8276 KB Output is correct
3 Correct 45 ms 8272 KB Output is correct