Submission #886540

#TimeUsernameProblemLanguageResultExecution timeMemory
886540dubabubaSandcastle 2 (JOI22_ho_t5)C++14
10 / 100
5075 ms31324 KiB
#include <algorithm> #include <iostream> #include <vector> #include <set> #include <map> using namespace std; typedef pair<int, int> pii; #define ff first #define ss second #define MP make_pair const int mxn = 5050; int a[mxn][mxn], n, m; pii pos[mxn]; void build() { map<int, int> mp; for(int i = 0; i < n; i++) for(int j = 0; j < m; j++) mp[a[i][j]]; int s = 0; for(auto &p : mp) p.second = s++; for(int i = 0; i < n; i++) for(int j = 0; j < m; j++) { a[i][j] = mp[a[i][j]]; pos[a[i][j]] = {i, j}; } } bool neighbour(int x, int y) { const pii &px = pos[x]; const pii &py = pos[y]; pii p; p.ff = px.ff - py.ff; p.ss = px.ss - py.ss; return (p.ff * p.ss == 0) && (abs(p.ff + p.ss) == 1); } bool can(int i1, int i2, int j1, int j2) { vector<int> v; for(int i = i1; i <= i2; i++) for(int j = j1; j <= j2; j++) v.push_back(a[i][j]); sort(v.begin(), v.end()); for(int i = 1; i < v.size(); i++) if(!neighbour(v[i], v[i - 1])) return 0; return 1; } int main() { cin >> n >> m; for(int i = 0; i < n; i++) for(int j = 0; j < m; j++) cin >> a[i][j]; build(); int ans = 0; for(int s = 0; s < n; s++) for(int e = s; e < n; e++) for(int l = 0; l < m; l++) for(int r = l; r < m; r++) { if(can(s, e, l, r)) { ans++; } } cout << ans << '\n'; return 0; }

Compilation message (stderr)

Main.cpp: In function 'bool can(int, int, int, int)':
Main.cpp:52:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |  for(int i = 1; i < v.size(); i++)
      |                 ~~^~~~~~~~~~
#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...