이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "garden.h"
#include "gardenlib.h"
#include<bits/stdc++.h>
using namespace std;
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 << "[" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define dbg(...) 0
#endif // LOCAL
#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 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 pb push_back
#define tcT template<class T
#define nl "\n"
#define fi first
#define se second
using ll = long long;
using vi = vector<int>;
using pi = pair<int,int>;
using str = string;
using db = long double;
tcT> using V = vector<T>;
tcT> using pqg = priority_queue<T,vector<T>,greater<T>>;
void setIO(string NAME = "") {
cin.tie(0)->sync_with_stdio(0);
if(sz(NAME)) {
freopen((NAME + ".inp").c_str(),"r",stdin);
freopen((NAME + ".out").c_str(),"w",stdout);
}
}
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; }
const int MOD = 1e9 + 7;
const ll INF = 1e18;
const int MX = 150005;
vi adj[MX<<1];
int fs[MX<<1], sc[MX<<1];
int nxt[MX<<1];
int dist[2][MX<<1];
int cycsz[2], cycDist[2][MX<<1];
bool vis[MX<<1];
int goal;
void dfs(int u, int id) {
if(~dist[id][u]) return;
if(~cycDist[id][u]) {
dist[id][u] = cycDist[id][u];
return;
}
if(u == goal) {
dist[id][u] = 0;
return;
}
dist[id][u] = MOD;
if(dist[id][nxt[u]] == -1) dfs(nxt[u], id);
ckmin(dist[id][u], dist[id][nxt[u]] + 1);
}
void count_routes(int N, int M, int P, int R[][2], int Q, int G[]) {
memset(fs, -1, sizeof fs);
memset(sc, -1, sizeof sc);
R0F(i, M) {
sc[R[i][0]] = fs[R[i][0]];
fs[R[i][0]] = R[i][1];
sc[R[i][1]] = fs[R[i][1]];
fs[R[i][1]] = R[i][0];
}
F0R(i, N<<1) {
if(i < N) {
if(fs[fs[i]] == i) {
nxt[i] = fs[i] + N;
}
else {
nxt[i] = fs[i];
}
}
else {
if(sc[i-N] == -1) {
nxt[i] = nxt[i-N];
}
else if(fs[sc[i-N]] == i-N) {
nxt[i] = sc[i-N] + N;
}
else nxt[i] = sc[i-N];
}
}
memset(cycDist, -1, sizeof cycDist);
memset(dist, -1, sizeof dist);
F0R(id, 2) {
memset(vis, false, sizeof vis);
int cur = P + id*N;
while(cur >= 0 && !vis[cur]) {
vis[cur] = 1;
cycDist[id][cur] = cycsz[id]++;
cur = nxt[cur];
}
F0R(i, N<<1) {
if(~cycDist[id][i]) {
cycDist[id][i] = (cycsz[id] - cycDist[id][i])%cycsz[id];
}
}
goal = -1;
if(cur != P + id*N) {
cycsz[id] = 0;
memset(cycDist[id], -1, sizeof cycDist[id]);
goal = P + id*N;
}
F0R(i, N) if(dist[id][i] == -1) dfs(i, id);
}
F0R(i, Q) {
int K = G[i];
bool ok = false;
int cnt = 0;
F0R(u, N) {
bool ok = false;
F0R(id, 2) {
ok |= (dist[id][u] == K || (cycsz[id] > 0 && K >= dist[id][u] && (K - dist[id][u])%cycsz[id] == 0));
}
cnt += ok;
}
answer(cnt);
}
}
컴파일 시 표준 에러 (stderr) 메시지
garden.cpp: In function 'void count_routes(int, int, int, int (*)[2], int, int*)':
garden.cpp:148:14: warning: unused variable 'ok' [-Wunused-variable]
148 | bool ok = false;
| ^~
garden.cpp: In function 'void setIO(std::string)':
garden.cpp:43:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
43 | freopen((NAME + ".inp").c_str(),"r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
garden.cpp:44:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
44 | freopen((NAME + ".out").c_str(),"w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |