# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
100296 | mraron | Konj (COCI19_konj) | C++14 | 109 ms | 15736 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<cassert>
#include<cassert>
#include<unordered_map>
#include<unordered_set>
#include<functional>
#include<queue>
#include<stack>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<sstream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<numeric>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define xx first
#define yy second
#define sz(x) (int)(x).size()
#define gc getchar
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mp make_pair
#ifndef ONLINE_JUDGE
# define LOG(x) (cerr << #x << " = " << (x) << endl)
#else
# define LOG(x) ((void)0)
#endif
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const double PI=3.1415926535897932384626433832795;
const ll INF = 1LL<<62;
const ll MINF = -1LL<<62;
template<typename T> T getint() {
T val=0;
char c;
bool neg=false;
while((c=gc()) && !(c>='0' && c<='9')) {
neg|=c=='-';
}
do {
val=(val*10)+c-'0';
} while((c=gc()) && (c>='0' && c<='9'));
return val*(neg?-1:1);
}
struct pt {
int xx,yy;
};
struct seg {
pt a,b;
};
const int M=312;
int Ok[M][M];
int Volt[M][M];
vector<pt> adj[M][M];
int ans[M][M];
int cntx[M];
int cnty[M];
void draw(pt A, pt B) {
ans[min(A.yy,B.yy)][min(A.xx,B.xx)]++;
ans[min(A.yy,B.yy)][max(A.xx,B.xx)+1]--;
ans[max(A.yy,B.yy)+1][max(A.xx,B.xx)+1]++;
ans[max(A.yy,B.yy)+1][min(A.xx,B.xx)]--;
/*for(int i=min(A.xx, B.xx);i<=max(A.xx,B.xx);++i) {
for(int j=min(A.yy, B.yy);j<=max(A.yy,B.yy);++j) {
ans[j][i]=1;
}
}*/
}
void flush() {
for(int i=0;i<M;++i) {
for(int j=0;j<M;++j) {
if(i>0) ans[i][j]+=ans[i-1][j];
if(j>0) ans[i][j]+=ans[i][j-1];
if(i>0 && j>0) ans[i][j]-=ans[i-1][j-1];
}
}
}
void dfs(pt akt) {
Volt[akt.xx][akt.yy]=1;
for(auto i:adj[akt.xx][akt.yy]) {
draw(akt,i);
if(!Volt[i.xx][i.yy]) {
dfs({i.xx,i.yy});
}
}
Volt[akt.xx][akt.yy]=2;
}
int main() {
IO;
int n;
cin>>n;
vector<seg> t(n);
for(int i=0;i<n;++i) {
cin>>t[i].a.xx>>t[i].a.yy;
cin>>t[i].b.xx>>t[i].b.yy;
}
pt T;
cin>>T.xx>>T.yy;
for(int i=0;i<n;++i) {
if(t[i].a.xx==t[i].b.xx && T.xx==t[i].a.xx && min(t[i].a.yy, t[i].b.yy)<=T.yy && T.yy<=max(t[i].a.yy, t[i].b.yy)) {
Ok[t[i].a.xx][t[i].a.yy]=1;
Ok[t[i].b.xx][t[i].b.yy]=1;
}
if(t[i].a.yy==t[i].b.yy && T.yy==t[i].a.yy && min(t[i].a.xx, t[i].b.xx)<=T.xx && T.xx<=max(t[i].a.xx, t[i].b.xx)) {
Ok[t[i].a.xx][t[i].a.yy]=1;
Ok[t[i].b.xx][t[i].b.yy]=1;
}
}
for(int i=0;i<n;++i) {
adj[t[i].a.xx][t[i].a.yy].push_back(t[i].b);
adj[t[i].b.xx][t[i].b.yy].push_back(t[i].a);
}
for(int i=0;i<M;++i) {
for(int j=0;j<M;++j) {
if(Ok[i][j] && !Volt[i][j]) {
dfs(pt{i,j});
}
}
}
flush();
for(int i=0;i<M;++i) {
for(int j=0;j<M;++j) {
cntx[i]+=ans[i][j];
cnty[j]+=ans[i][j];
}
}
int Lx, Rx, Ly, Ry;
for(Lx=0;Lx<M;++Lx) {if(cntx[Lx]>0) break ;}
for(Rx=M-1;Rx>=0;Rx--) {if(cntx[Rx]>0) break ;}
for(Ly=0;Ly<M;++Ly) {if(cnty[Ly]>0) break ;}
for(Ry=M-1;Ry>=0;Ry--) {if(cnty[Ry]>0) break ;}
for(int i=Rx;i>=Lx;--i) {
if(cntx[i]==0) continue ;
for(int j=Ly;j<=Ry;++j) {
if(cnty[j]==0) continue ;
cout<<(ans[i][j]?"#":".");
}cout<<"\n";
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |