Submission #524083

#TimeUsernameProblemLanguageResultExecution timeMemory
524083tube5429Vođe (COCI17_vode)C++14
120 / 120
476 ms96588 KiB
#include<bits/stdc++.h> using namespace std; #define FOR(i,a,b) for(int i = (a) ; i<(b) ; i++) #define F0R(i,a) FOR(i,0,a) #define ROF(i,a,b) for(int i = (b)-1 ; i>=(a) ; i--) #define R0F(i,a) ROF(i,0,a) #define REP(a) F0R(_,a) #define each(e,a) for(auto &e : (a)) #define sz(v) (int)(v).size() #define all(v) (v).begin(),(v).end() #define rall(v) (v).rbegin(),(v).rend() #define rsz resize #define pb push_back #define f first #define s second #define pf push_front #define ft front() #define bk back() #define eb emplace_back #define lb lower_bound #define ub upper_bound #define tcT template<class T #define tcTU tcT, class U #define nl "\n" using ll = long long; using vi = vector<int>; using vl = vector<ll>; using vb = vector<bool>; using pi = pair<int,int>; using vpi = vector<pi>; using str = string; using vs = vector<str>; using db = double; using pl = pair<ll,ll>; using pd = pair<db,db>; tcT> using V = vector<T>; tcT> using pqg = priority_queue<T,vector<T>,greater<T>>; tcTU> using PR = pair<T,U>; const int MOD = 1e9+7; const ll INF = 1e18; const int dx[] = {-1,0,1,0}, dy[] = {0,-1,0,1}; constexpr int bits(int x) { return x == 0 ? 0 : 31 - __builtin_clz(x); } constexpr bool onbit(int msk, int i) { return msk>>i&1; } constexpr ll p2(int x) { return 1LL<<x; } constexpr int pct(int x) { return __builtin_popcount(x); } constexpr int lg2(int x) { return x == 0 ? 0 : 31 - __builtin_clz(x); }; //int only tcT> bool ckmin(T&a, const T&b) { return b < a ? a = b,1 : 0; } tcT> bool ckmax(T&a, const T&b) { return b > a ? a = b,1 : 0; } ll cdiv(ll a, ll b) { return a/b+((a^b)>0&&a%b); } ll fdiv(ll a, ll b) { return a/b-((a^b)<0&&a%b); } tcTU> T fstTrue(T lo, T hi, U f) { hi++; assert(lo <= hi); while (lo < hi) { T mid = lo+(hi-lo)/2; f(mid) ? hi = mid : lo = mid+1; } return lo; } tcTU> T lstTrue(T lo, T hi, U f) { lo--; assert(lo <= hi); while (lo < hi) { T mid = lo+(hi-lo+1)/2; f(mid) ? lo = mid : hi = mid-1; } return lo; } tcT> void remDup(V<T> &v) { sort(all(v)); v.erase(unique(all(v)), end(v)); } void DBG() { cerr << "]\n"; } template<class H, class... T> void DBG(H h, T... t) { cerr << h; if(sizeof...(t)) cerr << ", "; DBG(t...); } #ifdef LOCAL #define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__) #else #define dbg(...) 0 #endif // LOCAL void setPrec() { cout << fixed << setprecision(16); } void setIO(string NAME = "") { cin.tie(0)->sync_with_stdio(0); setPrec(); if(sz(NAME)) { freopen((NAME + ".in").c_str(),"r",stdin); freopen((NAME + ".out").c_str(),"w",stdout); } } const int MX = 5e3+5; int N, M, K, dp[MX][MX], A[MX], lstNeg[MX], lstPos[MX]; void solve() { cin>>N>>M>>K; FOR(i,1,N+1) cin>>A[i]; FOR(i,1,N+1) { dp[i][M-1] = -1; lstNeg[i] = M-1; lstPos[i] = 100000; } R0F(i,M-1) { FOR(j,1,N+1) { int nxt = j+1; if(nxt == N+1) nxt = 1; int x = 0, y = 0; int p = lstPos[nxt]; if(p != 100000 && abs(i - p) <= K) x = 1; p = lstNeg[nxt]; if(p != 100000 && abs(i - p) <= K) y = 1; if(A[j] == A[nxt] && x) dp[j][i] = 1; else if(A[j] != A[nxt] && y) dp[j][i] = 1; else dp[j][i] = -1; } FOR(j,1,N+1) { if(dp[j][i] == 1) ckmin(lstPos[j], i); else ckmin(lstNeg[j], i); } } FOR(i,1,N+1) { if(dp[i][0] < 0) cout << (A[i] + 1)%2 << " "; else cout << A[i] << " "; } cout << nl; } int main() { setIO(); int t=1; //cin>>t; while(t-->0) { solve(); } return 0; }

Compilation message (stderr)

vode.cpp: In function 'void setIO(std::string)':
vode.cpp:93:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   93 |   freopen((NAME + ".in").c_str(),"r",stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
vode.cpp:94:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   94 |   freopen((NAME + ".out").c_str(),"w",stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...
#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...