QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#54673 | #4195. Looking for Waldo | Sa3tElSefr# | WA | 2ms | 3656kb | C++ | 2.4kb | 2022-10-10 03:24:48 | 2022-10-10 03:24:49 |
Judging History
answer
/// tban lecodes el bosta2
#pragma GCC optimize("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx,avx2,fma")
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define pb push_back
#define F first
#define S second
#define f(i, a, b) for(int i = a; i < b; i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define sz(x) (int)(x).size()
#define mp(x,y) make_pair(x,y)
#define popCnt(x) (__builtin_popcountll(x))
#define int ll
using ll = long long;
using ii = pair<int, int>;
using ull = unsigned long long;
const int N = 2e5+5, LG = 18, MOD = 1e9+7;
const long double PI = acos(-1);
const long double EPS = 1e-7;
const string TARGET = "WALDO";
vector<vector<char> > a;
vector<vector<int> > pref[5];
int n, m;
vector<vector<int> > build(char c) {
vector<vector<int> > pref(n + 1, vector<int>(m + 1, 0));
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= m; j++) {
pref[i][j] = (a[i][j] == c) + pref[i - 1][j] + pref[i][j - 1] - pref[i - 1][j - 1];
}
}
return pref;
}
int get(int r, int r2, int c, int c2, int idx) {
return pref[idx][r2][c2] - pref[idx][r - 1][c2] - pref[idx][r2][c - 1] + pref[idx][r - 1][c - 1];
}
bool check(int r, int r2, int c, int c2) {
for(int i = 0; i < 5; i++) {
if(get(r, r2, c, c2, i) == 0) return 0;
}
return 1;
}
void doWork() {
cin >> n >> m;
a = vector<vector<char>> (min(n + 1, m + 1), vector<char>(max(n + 1,m + 1)));
f(i,1,n+1)
f(j,1,m+1) {
if(n<m) cin >> a[i][j];
else cin >> a[j][i];
}
if(n > m) swap(n, m);
for(int i = 0; i < 5; i++) pref[i] = build(TARGET[i]);
ll ans = n * m + 1;
for(int r1 = 1; r1 <= n; r1++)
for(int r2 = 1; r2 <= n; r2++)
for(int c1 = 1, c2 = 1; c1 <= m; c1++) {
while(c2 <= m && !check(r1, r2, c1, c2))c2++;
if(c2 <= m && check(r1,r2,c1,c2)) {
ans = min(ans,(r2-r1+1)*(c2-c1+1));
}
}
if(ans > n * m) cout << "impossible\n";
else
cout << ans << '\n';
}
int32_t main() {
#ifdef ONLINE_JUDGE
ios_base::sync_with_stdio(0);
cin.tie(0);
#endif // ONLINE_JUDGE
int t = 1;
// cin >> t;
while (t--) {
doWork();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3568kb
input:
5 5 ABCDE FGHIJ KLMNO PQRST VWXYZ
output:
25
result:
ok single line: '25'
Test #2:
score: 0
Accepted
time: 2ms
memory: 3656kb
input:
5 10 ABCDEABCDE FGHIJFGHIJ KLMNOKLMNO PQRSTPQRST VWXYZVWXYZ
output:
20
result:
ok single line: '20'
Test #3:
score: -100
Wrong Answer
time: 2ms
memory: 3560kb
input:
5 10 WAALDLODOW AWWLAOODOW LOLADOWALO ADALLLWWOL WWOOAAAALO
output:
-14
result:
wrong answer 1st lines differ - expected: '5', found: '-14'