Submission #832703

#TimeUsernameProblemLanguageResultExecution timeMemory
832703sysiaGarden (JOI23_garden)C++17
6 / 100
311 ms18856 KiB
//Sylwia Sapkowska #include <bits/stdc++.h> #pragma GCC optimize("O3", "unroll-loops") using namespace std; void __print(int x) {cerr << x;} void __print(long long x) {cerr << x;} void __print(long double x) {cerr << x;} void __print(char x) {cerr << "'" << x << "'";} void __print(const char *x) {cerr << '"' << x << '"';} void __print(const string &x) {cerr << '"' << x << '"';} void __print(bool x) {cerr << (x ? "true" : "false");} template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ", "; __print(x.second); cerr << '}';} template<typename T> void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? ", " : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";} template <typename T, typename... V> void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);} #ifdef LOCAL #define debug(x...) cerr << "[" << #x << "] = ["; _print(x) #else #define debug(x...) #endif #define int long long typedef pair<int, int> T; const int oo = 1e18, oo2 = 1e9+7, K = 30; const int mod = 998244353; void solve(){ int n, m, d; cin >> n >> m >> d; vector<int>X, Y; int mx = 2*d; vector<vector<int>>pion(mx), poz(mx), p(mx); for (int i = 0; i<n; i++){ int x, y; cin >> x >> y; //4 punkty p[x].emplace_back(y); p[x+d].emplace_back(y); } vector<int>tab(d); int sum = 0; for (int i = 0; i<m; i++){ int a, b; cin >> a >> b; X.emplace_back(a); Y.emplace_back(b); tab[b]++; sum++; pion[a].emplace_back(i); pion[a+d].emplace_back(i); poz[b].emplace_back(i); } int R = -1; set<int>s; //indeksy pionowych int ans = oo; for (int L = 0; L < d; L++){ while (R+1 < 2*d && sum != n+m){ R++; //dodaj R-ty x for (auto y: p[R]) { tab[y]++; sum++; } for (auto i:pion[R]){ tab[Y[i]]--; s.insert(i); } // debug(R, tab, s, sum); if (sum == n+m){ break; } } if (sum == n+m){ debug(L, R); debug(tab); int r = -1; int curr = 0; for (int l = 0; l < d; l++){ while (curr < sum-(int)s.size()){ r = (r+1)%d; curr += tab[r]; } if (curr == sum-(int)s.size()){ ans = min(ans, (R-L+1)*(r >= l ? r-l+1 : (d-l)+(r+1))); } curr -= tab[l]; } } //usun L-ty x for (auto y: p[L]){ tab[y]--; sum--; } for (auto i: pion[L]){ s.erase(i); tab[Y[i]]++; } } cout << ans << "\n"; } int32_t main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t = 1; //cin >> t; while (t--) solve(); return 0; }
#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...