# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
100320 | ozneroL | Konj (COCI19_konj) | C++14 | 264 ms | 34680 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 <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vii;
#define F first
#define S second
#define ERR 1e-9
#if !ONLINE_JUDGE && !EVAL
#define dbg_var(x) cerr << #x << ": " << x << "\n";
#define dbg_iter(x, y) cerr << #x << ": " << print_iterable(x, y) << "\n";
#else
#define dbg_var(x)
#define dbg_iter(x, y)
#endif // ONLINE_JUDGE
template <typename T1, typename T2>
string print_iterable( T1 begin_iter, T2 end_iter){
bool first = true;
stringstream res;
res << "[ ";
for(; begin_iter != end_iter; ++begin_iter){
if(!first) res << ", ";
first = false;
res << *begin_iter;
}
res << " ]";
return res.str();
}
void aggMax(int & res, int x){ if(x > res)res = x; }
void aggMin(int & res, int x){ if(x < res)res = x; }
int II(){ int i; cin >> i; return i; }
void OI(int i){ cout << i; }
// constraints
const int MAXN = 310;
#define pb push_back
char grid[MAXN][MAXN];
void spread(int rI, int cI, int rF, int cF);
int minR, maxR, minC, maxC;
void print(){
for(int i=maxR; i>=minR; i--){
for(int j=minC; j<=maxC; j++)
cout << grid[i][j];
cout << "\n";
}
}
struct segment{
int cI, rI, cF, rF;
bool isDraw;
void draw(){
if(!isDraw){
isDraw = true;
minR = min(minR, min(rI,rF));
maxR = max(maxR, max(rI,rF));
minC = min(minC, min(cI,cF));
maxC = max(maxC, max(cI,cF));
if(rI == rF){
int cIt = cI, cFt = cF;
if(cIt > cFt) swap(cIt, cFt);
for(int i=cIt; i<=cFt; i++) grid[rI][i] = '#';
}else{
int rIt = rI, rFt = rF;
if(rIt > rFt) swap(rIt, rFt);
for(int i=rIt; i<=rFt; i++) grid[i][cI] = '#';
}
spread(rI, cI, rF, cF);
}
}
bool equals(int rI2, int cI2, int rF2, int cF2){
return rI == rI2 && cI == cI2 && rF2 == rF2 && cF == cF2;
}
void printS(){
cout << rI << "," << cI << " " << rF << "," << cF << "\n";
}
};
vector<segment> containT;
vector<segment> endPoints[MAXN][MAXN];
void spread(int rI, int cI, int rF, int cF){
for(segment & a : endPoints[rI][cI])
if(!a.equals(rI, cI, rF, cF))
a.draw();
for(segment & a : endPoints[rF][cF])
if(!a.equals(rI, cI, rF, cF))
a.draw();
}
bool isBetween(int p, int c1, int c2){
if(c1 > c2) swap(c1, c2);
return c1 <= p && p <= c2;
}
int main() {
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
//ios::sync_with_stdio(false);
//cin.tie(0);
minR = minC = INT_MAX;
int N = II();
vector<segment> s(N);
for(int i=0; i<N; i++){
int cI, rI, cF, rF;
cin >> cI >> rI >> cF >> rF;
s[i] = {cI, rI, cF, rF, false};
endPoints[rI][cI].pb(s[i]);
endPoints[rF][cF].pb(s[i]);
}
int cT = II(), rT = II();
for(segment & a : s){
if(a.rI == a.rF && a.rI == rT && isBetween(cT, a.cI, a.cF)){
/// horizontal segment
containT.pb(a);
}else if(a.cI == cT && isBetween(rT, a.rI, a.rF)){
/// vertical segment
containT.pb(a);
}
}
memset(grid, '.', sizeof grid);
/*for(int i=0; i<s.size(); i++){
draw(s[i]);
}*/
for(segment & a : containT){
a.draw();
}
print();
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |