Submission #955398

#TimeUsernameProblemLanguageResultExecution timeMemory
955398DuineMatching (CEOI11_mat)C++14
0 / 100
2054 ms29264 KiB
#include <bits/stdc++.h> using namespace std; int n, m, h[1000005]{}, tmp[1000005]{}, g[1000005]{}, posh[1000005]{}, posg[1000005]{}; int find_pos (int x) { int l = 1, r = n, mid; while (l <= r) { mid = l + ((r-l) >> 1); if (x == tmp[mid]) return mid; else if (x > tmp[mid]) l = mid+1; else r = mid-1; } } int main () { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m; for (int i = 1; i <= n; ++i) { cin >> h[i]; tmp[i] = h[i]; } for (int i = 1; i <= m; ++i) cin >> g[i]; sort (tmp+1, tmp+n+1); for (int i = 1; i <= n; ++i) posh[i] = find_pos(h[i]); for (int i = 1; i <= n; ++i) tmp[i] = g[i]; sort (tmp+1, tmp+n+1); for (int i = 1; i <= n; ++i) posg[i] = find_pos(g[i]); vector <int> res; for (int i = 1; i <= m-n+1; ++i) { bool check = true; for (int j = 1; j <= n; ++j) if (posg[i+j-1] != posh[j]) { check = false; break; } if (check) res.push_back(i); for (int j = 1; j < n; ++j) if (g[i] < g[i+j]) --posg[i+j]; int mn = n; for (int j = 1; j < n; ++j) if (g[i+n] < g[i+j]) { mn = min (mn, posg[i+j]); ++posg[i+j]; } posg[i+n] = mn; } cout << res.size() << '\n'; for (int i = 0; i < res.size(); ++i) cout << res[i] << ' '; return 0; }

Compilation message (stderr)

mat.cpp: In function 'int main()':
mat.cpp:62:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |     for (int i = 0; i < res.size(); ++i)
      |                     ~~^~~~~~~~~~~~
mat.cpp: In function 'int find_pos(int)':
mat.cpp:17:1: warning: control reaches end of non-void function [-Wreturn-type]
   17 | }
      | ^
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...