Submission #171288

# Submission time Handle Problem Language Result Execution time Memory
171288 2019-12-28T08:03:09 Z mehrdad_sohrabi Alternating Current (BOI18_alternating) C++14
0 / 100
3000 ms 7396 KB
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define pii pair < ll , ll >
#define F first
#define S second
#define endl '\n'
#define int long long
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
using namespace std;
/// khodaya komak kon
/// ya navid navid
const int N=1e5+100;
vector <pii> g[N];
ll ans[N];
vector <pii> yal;
ll n,m;
ll cng(ll x){
    for (int i=0;i<yal.size();i++){
        ll u=yal[i].F,v=yal[i].S;
        u--;
        v--;
        if (u<=0) u+=n;
        if (v<=0) v+=n;
        yal[i].F=u;
        yal[i].S=v;

    }
    return 0;
}
ll solve(){
    for (int i=1;i<=n;i++){
        g[i].clear();
    }
    for (int i=0;i<m;i++){
        ll a,b;
        a=yal[i].F;
        b=yal[i].S;
        g[a].pb({b,i});
    }
    for (int i=1;i<=n;i++){
        sort(g[i].begin(),g[i].end());
        reverse(g[i].begin(),g[i].end());
    }
    ll cnt1=0,cnt=0;
    for (int i=1;i<=n;i++){
        for (int j=0;j<g[i].size();j++){
            ll k=g[i][j].F;
            if (cnt<cnt1){
                if (cnt>=i-1){
                    cnt=max(cnt,k);
                    ans[g[i][j].S]=0;
                }
                continue;
            }
            else{
                if (cnt1>=i-1){
                    cnt1=max(cnt1,k);
                    ans[g[i][j].S]=1;
                }

            }
        }
    }

    if (cnt==n && cnt1==n){
        for (int i=0;i<m;i++){
            cout << ans[i];
        }
        return 1;
    }
    return 0;
}
int32_t main(){
    cin >> n >> m;
    for (int i=0;i<m;i++){
        ll a,b;
        cin >> a >> b;
        yal.pb({a,b});
    }
    for (int i=1;i<=n;i++){
        ll t=solve();
        cng(i);
        if (t) return 0;
    }

    cout << "impossible" << endl;

}


Compilation message

alternating.cpp: In function 'll cng(ll)':
alternating.cpp:22:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i=0;i<yal.size();i++){
                  ~^~~~~~~~~~~
alternating.cpp: In function 'll solve()':
alternating.cpp:50:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int j=0;j<g[i].size();j++){
                      ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2680 KB Output is correct
2 Correct 5 ms 2680 KB Output is correct
3 Incorrect 13 ms 2680 KB 'impossible' claimed, but there is a solution
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2680 KB Output is correct
2 Correct 5 ms 2680 KB Output is correct
3 Incorrect 13 ms 2680 KB 'impossible' claimed, but there is a solution
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2680 KB Output is correct
2 Correct 5 ms 2680 KB Output is correct
3 Incorrect 13 ms 2680 KB 'impossible' claimed, but there is a solution
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 103 ms 7396 KB Output is correct
2 Correct 5 ms 2680 KB Output is correct
3 Execution timed out 3037 ms 5112 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2680 KB Output is correct
2 Correct 5 ms 2680 KB Output is correct
3 Incorrect 13 ms 2680 KB 'impossible' claimed, but there is a solution
4 Halted 0 ms 0 KB -