제출 #369663

#제출 시각아이디문제언어결과실행 시간메모리
3696638e7Bitaro’s Party (JOI18_bitaro)C++14
14 / 100
2077 ms127908 KiB
//Challenge: Accepted #include <unistd.h> #include <iostream> #include <algorithm> #include <utility> #include <vector> #define ll long long #define maxn 100005 #define pii pair<int, int> #define ff first #define ss second using namespace std; inline char RC(){ const int S = 1<<20; static char buf[S], *p = buf, *q = buf; if(p==q&&(q=(p=buf)+read(0, buf,S))==buf) return -1; return *p++; } inline void rint(int &ret) { char c; ret = 0; do {c = RC();} while (c < '0' || c > '9'); do {ret = (ret<<3)+(ret<<1) + c-'0';c=RC();} while (c>='0'&&c<='9'); } char OB[1<<20]; int outp; inline void pint(int a) { int d = -1; if (a < 0) OB[outp++] = '-', a = -a; if (!a) {OB[outp++] = '0';OB[outp++] = '\n';return;} char c[19]; while (a) {c[++d] = '0' + a%10;a /= 10;} for (int i=d;i >= 0;i--) OB[outp++] = c[i]; OB[outp++] = '\n'; } const int siz = 140; vector<int> adj[maxn], from[maxn]; vector<pii> pnt[maxn], tmp; inline bool cmp (pii a, pii b) { return a.ss > b.ss; } int dp[maxn]; bool part[maxn], found[maxn]; void getdp(int n, int id) { for (int i = 1;i <= id;i++) dp[i] = 0; for (int i = 1;i <= id;i++) { for (int v:adj[i]) { dp[v] = max(dp[v], (dp[i] == 0 ? (part[i] ? -1 : 0) : dp[i]) + 1); } } } void merge(int a, int b) { vector<pii> ret; int n = pnt[a].size(), m = pnt[b].size(), ind = 0; for (int i = 0;i < n;i++) { while (ind < m && pnt[b][ind].ss + 1 > pnt[a][i].ss) { if (!found[pnt[b][ind].ff]) { found[pnt[b][ind].ff] = 1; ret.push_back(make_pair(pnt[b][ind].ff, pnt[b][ind].ss + 1)); } ind++; if (ret.size() > siz) break; } if (!found[pnt[a][i].ff]) { found[pnt[a][i].ff] = 1; ret.push_back(pnt[a][i]); } if (ret.size() > siz) break; } while (ind < m) { if (!found[pnt[b][ind].ff]) { found[pnt[b][ind].ff] = 1; ret.push_back(make_pair(pnt[b][ind].ff, pnt[b][ind].ss + 1)); } ind++; if (ret.size() > siz) break; } for (auto i:ret) found[i.ff] = 0; if (ret.size() > siz) ret.resize(siz); pnt[a] = ret; } int main() { ios_base::sync_with_stdio(0);cin.tie(0); int n, m, q; rint(n), rint(m), rint(q); for (int i = 0;i < m;i++) { int a, b; rint(a), rint(b); adj[a].push_back(b); from[b].push_back(a); } for (int i = 1;i <= n;i++) { pnt[i].push_back(make_pair(i, 0)); for (int v:from[i]) { merge(i, v); } } getdp(n, n); while (q--) { int ind, yi; rint(ind), rint(yi); vector<int> val; for (int i = 0;i < yi;i++) { int x; rint(x); if (x <= ind) part[x] = 1, val.push_back(x); } if (yi >= siz) { getdp(n, ind); if (part[ind] && dp[ind] == 0) pint(-1); else pint(dp[ind]); } else { int ans = -1; for (auto v:pnt[ind]) { if (!part[v.ff]) ans = max(ans, v.ss); } pint(ans); } for (int i:val) part[i] = 0; } write(1, OB, outp); } /* 5 6 3 1 2 2 4 3 4 1 3 3 5 4 5 4 1 1 5 2 2 3 2 3 1 4 5 */

컴파일 시 표준 에러 (stderr) 메시지

bitaro.cpp: In function 'int main()':
bitaro.cpp:127:7: warning: ignoring return value of 'ssize_t write(int, const void*, size_t)', declared with attribute warn_unused_result [-Wunused-result]
  127 |  write(1, OB, outp);
      |  ~~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...