Submission #364203

#TimeUsernameProblemLanguageResultExecution timeMemory
364203Andyvanh1Alternating Current (BOI18_alternating)C++14
0 / 100
28 ms3968 KiB
using namespace std; // 17.4.1.2 Headers // C #ifndef _GLIBCXX_NO_ASSERT #include <cassert> #endif #include <cctype> #include <cerrno> #include <cfloat> #include <ciso646> #include <climits> #include <clocale> #include <cmath> #include <csetjmp> #include <csignal> #include <cstdarg> #include <cstddef> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #if __cplusplus >= 201103L #include <ccomplex> #include <cfenv> #include <cinttypes> #include <cstdbool> #include <cstdint> #include <ctgmath> #include <cwchar> #include <cwctype> #endif // C++ #include <algorithm> #include <bitset> #include <complex> #include <deque> #include <exception> #include <fstream> #include <functional> #include <iomanip> #include <ios> #include <iosfwd> #include <iostream> #include <istream> #include <iterator> #include <limits> #include <list> #include <locale> #include <map> #include <memory> #include <new> #include <numeric> #include <ostream> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdexcept> #include <streambuf> #include <string> #include <typeinfo> #include <utility> #include <valarray> #include <vector> #if __cplusplus >= 201103L #include <array> #include <atomic> #include <chrono> #include <condition_variable> #include <forward_list> #include <future> #include <initializer_list> #include <mutex> #include <random> #include <ratio> #include <regex> #include <scoped_allocator> #include <system_error> #include <thread> #include <tuple> #include <typeindex> #include <type_traits> #include <unordered_map> #include <unordered_set> #endif int nn; bool check(vector<pair<int,int>> vt){ int n = vt.size(); if(vt[0].first!=1){ return false; } for(int i = 1; i < n; i++){ if(vt[i].first>vt[i-1].second+1){ return false; } } return true; } void solve(){ int m; cin>>nn>>m; vector<pair<pair<int,int>,int>> ps; for(int i = 0; i < m; i++){ int a, b; cin>>a>>b; ps.push_back({{a,b},i}); } if(m==1){ cout<<"impossible"; return; } sort(ps.begin(),ps.end()); vector<pair<int,int>> as; vector<pair<int,int>> bs; int maxA = 0; int maxB = 0; vector<int> ans(m); for(int i = 0; i < m; i++){ if(maxA>maxB){ bs.push_back(ps[i].first); maxB = max(maxB, ps[i].first.second); ans[ps[i].second] = 1; }else{ as.push_back(ps[i].first); maxA = max(maxA,ps[i].first.second); ans[ps[i].second] = 0; } } if(check(as)&&check(bs)&&maxA==nn&& maxB==nn){ for(int i = 0; i < m; i++){ cout<<ans[i]; } }else{ cout<<"impossible"; } } int main() { ios::sync_with_stdio(0); cin.tie(0); int tc = 1; //read(tc); while(tc--) { //write("Case #", i+1, ": "); solve(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...