Submission #1247103

#TimeUsernameProblemLanguageResultExecution timeMemory
1247103ErJMosaic (IOI24_mosaic)C++20
27 / 100
199 ms58900 KiB
#include "mosaic.h" #include <bits/stdc++.h> using namespace std; #define ll long long #define vi vector<ll> #define vvi vector<vi> #define pp pair<ll, ll> #define vp vector<pp> vi small(std::vector<int> X, std::vector<int> Y, std::vector<int> T, std::vector<int> B, std::vector<int> L, std::vector<int> R){ ll n = X.size(); vvi grid(n, vi(n, 0)); for(int i = 0; i < n; i++){ grid[i][0] = X[i]; grid[0][i] = Y[i]; } for(int i = 1; i < n; i++){ for(int j = 1; j < n; j++){ if(grid[i - 1][j] == 0 && grid[i][j - 1] == 0){ grid[i][j] = 1; } } } vvi pref(n + 1, vi(n + 1, 0)); for(int i = 0; i < n; i++){ for(int j = 0; j < n; j++){ pref[i + 1][j + 1] = pref[i + 1][j] + pref[i][j + 1] - pref[i][j] + grid[i][j]; /*if(grid[i][j] == 0){ cout << '.'; }else{ cout << '#'; }*/ } //cout << '\n'; } ll q = (int)T.size(); vi C(q, 0); for(int i = 0; i < q; i++){ C[i] = pref[R[i] + 1][B[i] + 1] - pref[R[i] + 1][T[i]] - pref[L[i]][B[i] + 1] + pref[L[i]][T[i]]; } return C; } vi mosaic(std::vector<int> X, std::vector<int> Y, std::vector<int> T, std::vector<int> B, std::vector<int> L, std::vector<int> R) { ll n = X.size(); ll period = 10; if(n < period){ return small(X, Y, T, B, L, R); } vvi gridRow(n, vi(period, 0)), gridCol(period, vi(n, 0)); for(int i = 0; i < n; i++){ gridRow[i][0] = X[i]; } for(int i = 0; i < gridRow[0].size(); i++){ gridRow[0][i] = Y[i]; } for(int i = 1; i < gridRow.size(); i++){ for(int j = 1; j < gridRow[i].size(); j++){ if(gridRow[i - 1][j] == 0 && gridRow[i][j - 1] == 0){ gridRow[i][j] = 1; } } } for(int i = 0; i < n; i++){ gridCol[0][i] = Y[i]; } for(int i = 0; i < gridCol.size(); i++){ gridCol[i][0] = X[i]; } for(int i = 1; i < gridCol.size(); i++){ for(int j = 1; j < gridCol[i].size(); j++){ if(gridCol[i - 1][j] == 0 && gridCol[i][j - 1] == 0){ gridCol[i][j] = 1; } } } set<ll> black; for(int i = period - 1; i < n; i++){ if(gridRow[i][period - 1] == 1){ black.insert(i - period + 1); } } for(int i = period - 1; i < n; i++){ if(gridCol[period - 1][i] == 1){ black.insert(period - 1 - i); } } ll q = (int)T.size(); vi C(q, 0); for(int i = 0; i < q; i++){ if(L[i] < period){ if(gridCol[L[i]][T[i]]) C[i] = 1; } else if(T[i] < period){ if(gridRow[L[i]][T[i]]) C[i] = 1; } else if(black.count(L[i] - T[i])) C[i] = 1; } return C; }
#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...