이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
///huynhocute123///
#include<bits/stdc++.h>
using namespace std;
#define S second
#define F first
#define pii pair<int,int>
#define piii pair<int,pair<int,int>>
#define pb push_back
#define pi M_PI
#define FOR(i, a, b) for(int i = a; i <= b; ++i)
#define REP(i, a, b) for(int i = b; i >= a; --i)
#define ALL(v) v.begin(),v.end()
#define inp(name) if(fopen(name, "r")) freopen(name, "r", stdin);
#define out(name) if(fopen(name, "w")) freopen(name, "w", stdout);
//random_device rd;
//mt19937 rng(rd());
//#pragma GCC optimize ("O3")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("popcnt")
//#define int long long
const int maxN = 2 * 1e5 + 9 ;
const int modd = 1e9 + 7;
const int base = 2309;
const int MAX = 1e9+9;
void minimize(int &u, int v){
if(v < u) u = v;
}
void maximize(int &u, int v){
if(v > u) u = v;
}
int n, k, t, m, res, a[maxN], crash[maxN];
int l, r;
bool vis[maxN];
vector<piii> e;
vector<piii> col[maxN];
struct node{
int x, y ,ct, sum;
char id;
} ship[maxN];
void connect(int i ,int j){
int tmp = (abs(ship[i].x - ship[j].x) + abs(ship[i].y - ship[j].y))/2;
// cout << tmp;
if(ship[i].id == 'N'){
if(ship[j].id =='S'){
if(ship[i].y - ship[j].y == 2*tmp)e.pb({tmp, {i ,j}});
}
if(ship[j].id == 'W'){
if(ship[i].x + tmp ==ship[j].x && ship[i].y - tmp == ship[j].y)e.pb({tmp, {i ,j}});
}
if(ship[j].id == 'E'){
if(ship[i].x - tmp ==ship[j].x && ship[i].y - tmp == ship[j].y)e.pb({tmp, {i ,j}});
}
return;
}
if(ship[i].id == 'S'){
if(ship[j].id =='N'){
if(-ship[i].y + ship[j].y == 2*tmp)e.pb({tmp, {i ,j}});
}
if(ship[j].id == 'W'){
if(ship[i].x + tmp ==ship[j].x && ship[i].y + tmp == ship[j].y)e.pb({tmp, {i ,j}});
}
if(ship[j].id == 'E'){
if(ship[i].x - tmp ==ship[j].x && ship[i].y + tmp == ship[j].y)e.pb({tmp, {i ,j}});
}
return;
}
if(ship[i].id == 'W'){
if(ship[j].id =='E'){
if(ship[i].x -ship[j].x == 2*tmp)e.pb({tmp, {i ,j}});
}
if(ship[j].id == 'N'){
if(ship[i].x - tmp ==ship[j].x && ship[i].y + tmp == ship[j].y)e.pb({tmp, {i ,j}});
}
if(ship[j].id == 'S'){
if(ship[i].x - tmp ==ship[j].x && ship[i].y - tmp == ship[j].y)e.pb({tmp, {i ,j}});
}
}
if(ship[i].id == 'E'){
if(ship[j].id =='W'){
if(-ship[i].x +ship[j].x == 2*tmp)e.pb({tmp, {i ,j}});
}
if(ship[j].id == 'N'){
if(ship[i].x + tmp ==ship[j].x && ship[i].y + tmp == ship[j].y)e.pb({tmp, {i ,j}});
}
if(ship[j].id == 'S'){
if(ship[i].x + tmp ==ship[j].x && ship[i].y - tmp == ship[j].y)e.pb({tmp, {i ,j}});
}
}
}
void sub1(){
for(int i =1;i <= n ;i++){
for(int j = i + 1; j <= n; j++){
connect(i ,j);
}
}
sort(ALL(e));
for(auto x : e){
int u = x.S.F, v= x.S.S, TIME = x.F;
if(crash[u] == 0 && crash[v] == 0){
crash[u] = TIME;
crash[v] = TIME;
continue;
}
if(crash[u] == 0 && crash[v] == TIME){
crash[u] =TIME;
}
if(crash[v] == 0 && crash[u] == TIME){
crash[v] =TIME;
}
}
for(int i = 1; i <= n ;i++)if(!crash[i])cout << i << '\n';
// for(auto x : e)cout << x.F << " " ;
}
void compress(vector<int>& x){
set<int> st;
for(auto X : x)st.insert(X);
vector<int> tmp (ALL(st));
for(int i= 1;i <= n ;i++){
ship[i].sum = lower_bound(ALL(tmp), ship[i].sum) - tmp.begin() + 1;
}
}
void sub2(){
vector<int> tmp, ans;
for(int i =1; i <= n ;i++){
tmp.pb(ship[i].x + ship[i].y);
ship[i].sum = ship[i].x + ship[i].y;
}
compress(tmp);
int mx =0;
for(int i =1;i <= n ;i++){
col[ship[i].sum].pb({ship[i].x , {i , (ship[i].id == 'E' ? 1 : -1) } });
maximize(mx, ship[i].sum);
}
stack<pii>st;
// cout << st.top().S;
for(int i= 1;i <= mx ;i++){
sort(ALL(col[i]));
// for(auto x : col[i])cout << x.S.S << " ";
// cout << '\n';
for(auto x : col[i]){
int id = x.S.F, typ = x.S.S;
if(st.empty())st.push({id, typ});
else{
if(typ == 1)st.push({id, typ});
else {
if(st.top().S == 1)st.pop();
}
}
}
while(st.size()){
ans.pb(st.top().F);
// cout << st.top().F << " ";
st.pop();
}
}
sort(ALL(ans));
for(auto x :ans)cout << x << '\n';
}
void solve(){
cin >> n;
for(int i =1;i <= n ;i++){
cin >> ship[i].x >> ship[i].y >> ship[i].id;
ship[i].ct =i;
}
// sub2();
if(n <= 5009)sub1();
else sub2();
}
signed main(){
// freopen("name.inp","r",stdin);
// freopen("name.out","w",stdout);
ios_base::sync_with_stdio(false);
cin.tie(0);
inp("task.inp");
t = 1;
// cin >> t;
while( t-- )solve();
}
컴파일 시 표준 에러 (stderr) 메시지
Main.cpp: In function 'int main()':
Main.cpp:13:47: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
13 | #define inp(name) if(fopen(name, "r")) freopen(name, "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~
Main.cpp:183:5: note: in expansion of macro 'inp'
183 | inp("task.inp");
| ^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |