답안 #213187

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
213187 2020-03-25T07:24:14 Z toxic_hack Mostovi (COI14_mostovi) C++14
10 / 100
696 ms 22264 KB
// g++ -std=c++14

/*

Today might be the chance to grasp the chance to let your talent bloom.
May be tomorrow, the day after, or next year...
May be even when you are 30. I'm not sure if physique has anything to do with it
but if you think that it will never come, it probably never will.

- Tooru Oikawa.

*/


#include<bits/stdc++.h>

typedef long long ll;
typedef long double lld;
using namespace std;

#define endl "\n"
#define fi first
#define se second
#define MEMS(a,b) memset(a,b,sizeof(a))
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define __ freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define all(c) c.begin(),c.end()
#define pii pair<int, int>

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rand(int l, int r)
{
	uniform_int_distribution<int> uid(l, r);
	return uid(rng);
}

#define tr(...) cout<<__FUNCTION__<<' '<<__LINE__<<" = ";trace(#__VA_ARGS__, __VA_ARGS__)
template<typename S, typename T>
ostream& operator<<(ostream& out,pair<S,T> const& p){out<<'('<<p.fi<<", "<<p.se<<')';return out;}

template<typename T>
ostream& operator<<(ostream& out,vector<T> const& v){
ll l=v.size();for(ll i=0;i<l-1;i++)out<<v[i]<<' ';if(l>0)out<<v[l-1];return out;}

template <typename T>
ostream &operator<<(ostream &out, set<T> const &v) {
    for (auto i = v.begin(); i != v.end(); i++)
        out << (*i) << ' ';
    return out;
}
template <typename T>
ostream &operator<<(ostream &out, multiset<T> const &v) {
    for (auto i = v.begin(); i != v.end(); i++)
        out << (*i) << ' ';
    return out;
}
template <typename T, typename V>
ostream &operator<<(ostream &out, map<T, V> const &v) {
    for (auto i = v.begin(); i != v.end(); i++)
        out << "\n" << (i->first) <<  ":"  << (i->second);
    return out;
}

template<typename T>
void trace(const char* name, T&& arg1){cout<<name<<" : "<<arg1<<endl;}

template<typename T, typename... Args>
void trace(const char* names, T&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma-names)<<" : "<<arg1<<" | ";trace(comma+1,args...);}

int n, m;



void no() {
    cout << "NE" << endl;
}

void yes() {
    cout << "DA" << endl;
}
const int inf = 1e9 + 1;

map<int, int> bridge;

int get_after(int a, set<int> &s) {
    auto itr = s.lower_bound(a);
    if (itr == s.end()) return -1;
    else {
        return (*itr);
    }
}

int get_before(int a, set<int> &s) {
    auto itr = s.lower_bound(a);
    if (itr == s.begin()) {
        if (*itr == a) return a;
        else return -1;
    } else if (itr == s.end()) {
        itr--;
        if (*itr <= a) return *itr;
        else return -1;
    } else {
        if (*itr == a) return a;
        else {
            itr--;
            if (*itr <= a) return *itr;
            else return -1;
        }
    }
} 

set<int> bb;
set<int> nb, sb;
bool reach(int a, int b) {
    // tr(a, b);
    if (a == b) return 1;
    if (a <= n && b <= n) {
        if (b > a) {
            int x = get_after(a, bb);
            if (x == -1 || x >= b) return 1;
            else return 0;
        } else {
            int x = get_after(a, nb);
            int y = get_after(a, bb);
            if (x == -1) return 0;
            else {
                int opp = bridge[x];
                if (reach(a, x) && reach(opp, b)) return 1;
                else return 0;
            }
        }
    } else if (a > n && b > n) {
        if (b < a) {
            int x = get_before(a, bb) + 1;
            if (x == -1 || x <= b) return 1;
            else return 0;
        } else {
            int x = get_before(a, sb);
            int y = get_before(a, bb);
            // tr(x, y);
            if (x == -1) return 0;
            else {
                int opp = bridge[x];
                if (reach(a, x) && reach(opp, b)) return 1;
                else return 0;
            }
        }
    } else if (a <= n && b > n) {
        int x = get_after(b, sb);
        int z = get_after(a, nb);
        // tr(x, y, z);
        if (x == -1 || z == -1) return 0;
        else {
            int opp = bridge[x];
            opp = max(opp, z);
            int opp2 = bridge[opp];
            if (reach(a, opp) && reach(opp2, b)) return 1;
            else return 0;
        }
    } else {
        int x = get_before(b, nb);
        int z = get_before(a, sb);
        if (x == -1 || z == -1) return 0;
        else {
            int opp = bridge[x];
            opp = min(opp, z);
            int opp2 = bridge[opp];
            if (reach(a, opp) && reach(opp2, b)) return 1;
            else return 0;
        }
    }
}

int solve() {
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        char c;
        int g1, g2;
        cin >> c;
        cin >> g1 >> g2;
        if (c == 'Q') {
            if (reach(g1, g2)) yes();
            else no();
        } else if (c == 'A') {
            if (g1 > g2) {
                swap(g1, g2);
            }
            sb.insert(g2);
            nb.insert(g1);
            bridge[g1] = g2;
            bridge[g2] = g1;

        } else {
            if (g1 > g2) {
                swap(g1, g2);
            }
            if (g1 > n) {
                bb.insert(g1);
            } else {
                bb.insert(g1);
            }
        }   
    }
    return 0;
}

int32_t main(){ 
    int t;
    // cin >> t;
    t = 1;
    while (t--) solve();
}

Compilation message

mostovi.cpp: In function 'bool reach(int, int)':
mostovi.cpp:125:17: warning: unused variable 'y' [-Wunused-variable]
             int y = get_after(a, bb);
                 ^
mostovi.cpp:140:17: warning: unused variable 'y' [-Wunused-variable]
             int y = get_before(a, bb);
                 ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 384 KB Output isn't correct
2 Incorrect 8 ms 384 KB Output isn't correct
3 Incorrect 7 ms 384 KB Output isn't correct
4 Incorrect 7 ms 512 KB Output isn't correct
5 Correct 8 ms 640 KB Output is correct
6 Incorrect 7 ms 384 KB Output isn't correct
7 Incorrect 651 ms 17016 KB Output isn't correct
8 Incorrect 677 ms 16760 KB Output isn't correct
9 Incorrect 610 ms 15224 KB Output isn't correct
10 Incorrect 696 ms 22264 KB Output isn't correct