Submission #250679

#TimeUsernameProblemLanguageResultExecution timeMemory
250679kingfran1907Bob (COCI14_bob)C++14
0 / 120
173 ms8260 KiB
#include <bits/stdc++.h> using namespace std; typedef long long llint; const int maxn = 1010; int n, m; int niz[maxn][maxn]; int cn[maxn][maxn]; vector< int > v; int sol[maxn]; stack< llint > p, q; llint cal() { while (!q.empty()) {q.pop(); p.pop();} llint out = 0; llint tren = 0; for (int i = 0; i < v.size(); i++) { llint cnt = 1; while (!p.empty() && p.top() >= v[i]) { llint ac = q.top(); q.pop(); llint val = p.top(); p.top(); cnt += ac; tren -= ac * (val - v[i]); } tren += v[i]; out += tren; } v.clear(); return out; } int main() { scanf("%d%d", &n, &m); for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) scanf("%d", &niz[i][j]); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (i == 0) cn[i][j] = 1; else { if (niz[i][j] == niz[i - 1][j]) cn[i][j] = 1 + cn[i - 1][j]; else cn[i][j] = 1; } } } llint sol = 0; for (int i = 0; i < n; i++) { v.push_back(cn[i][0]); for (int j = 1; j < m; j++) { if (niz[i][j - 1] != niz[i][j]) sol += cal(); v.push_back(cn[i][j]); } sol += cal(); } printf("%lld", sol); return 0; }

Compilation message (stderr)

bob.cpp: In function 'llint cal()':
bob.cpp:20:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < v.size(); i++) {
                     ~~^~~~~~~~~~
bob.cpp: In function 'int main()':
bob.cpp:37:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &n, &m);
     ~~~~~^~~~~~~~~~~~~~~~
bob.cpp:40:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d", &niz[i][j]);
             ~~~~~^~~~~~~~~~~~~~~~~~
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...