# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1019346 |
2024-07-10T18:05:36 Z |
mindiyak |
Rectangles (IOI19_rect) |
C++14 |
|
5000 ms |
343532 KB |
#include "rect.h"
#include <bits/stdc++.h>
#include <string>
#include <iostream>
#include <cmath>
#include <numeric>
#pragma GCC optimize("O1,O2,O3,Ofast,unroll-loops")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<int, int> pl;
typedef pair<ld, ld> pd;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<ld> vd;
typedef vector<long> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
#define FOR(i, a, b) for (int i = a; i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define FORd(i, a, b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i, a) for (int i = (a)-1; i >= 0; i--)
#define trav(a, x) for (auto &a : x)
#define uid(a, b) uniform_int_distribution<int>(a, b)(rng)
#define len(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define F first
#define nl endl
#define S second
#define lb lower_bound
#define ub upper_bound
#define aint(x) x.begin(), x.end()
#define raint(x) x.rbegin(), x.rend()
#define ins insert
const int MOD = 1000000007;
int N,M;
vvi arr;
ll ans = 0;
void dfs(int a,int b){
if(arr[a][b] == 1)return;
queue<pi> pq;
pq.push({a,b});
vpi nodes;
vi r(N,0),c(M,0);
set<pi> visited;
bool can = true;
int row = 0,column = 0,rowc = 0,colc = 0;
// cout << a << " " << b << endl;
while(!pq.empty()){
pi node = pq.front();pq.pop();
if(visited.count(node))continue;
if(node.F == 0 && arr[node.F][node.S] == 0)can = false;
if(node.S == 0 && arr[node.F][node.S] == 0)can = false;
if(node.F == (N-1) && arr[node.F][node.S] == 0)can = false;
if(node.S == (M-1) && arr[node.F][node.S] == 0)can = false;
if(node.F > 0 && node.F < (N-1) && node.S > 0 && node.S < (M-1) && arr[node.F][node.S] == 0){
visited.insert(node);
nodes.pb(node);
r[node.F] += 1;
c[node.S] += 1;
pq.push({node.F-1,node.S});
pq.push({node.F+1,node.S});
pq.push({node.F,node.S-1});
pq.push({node.F,node.S+1});
}
}
FOR(i,0,N){
if(r[i] == 0)continue;
if(row!=0 && row!=r[i]){
can = false;
break;
}
row = r[i];
rowc++;
}
FOR(i,0,M){
if(can == false)break;
if(c[i] == 0)continue;
if(column!=0 && column!=c[i]){
can = false;
break;
}
column = c[i];
colc++;
}
// for(int i:r)cout << i << " ";
// cout << " - " << row << " - " << rowc << endl;
// for(int i:c)cout << i << " ";
// cout << " - " << column << " - " << colc << endl;
// cout << can << endl;
if(can){
ans += 1;
}
for(auto node:nodes)arr[node.F][node.S] = 1;
// for(auto as:arr){
// for(auto aas:as){{
// cout << aas << " ";
// }}cout << endl;
// }
// cout << endl;
}
ll count_rectangles(vvi a) {
N = a.size();M = a[0].size();
// cout << endl;
arr = a;
FOR(i,1,N-1){
FOR(j,1,M-1){
dfs(i,j);
}
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
528 KB |
Output is correct |
2 |
Correct |
3 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
604 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Incorrect |
4 ms |
348 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
432 KB |
Output is correct |
2 |
Correct |
719 ms |
39792 KB |
Output is correct |
3 |
Correct |
1755 ms |
85896 KB |
Output is correct |
4 |
Correct |
1834 ms |
86096 KB |
Output is correct |
5 |
Correct |
1891 ms |
86100 KB |
Output is correct |
6 |
Correct |
3018 ms |
141228 KB |
Output is correct |
7 |
Execution timed out |
5038 ms |
343532 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |