제출 #908060

#제출 시각아이디문제언어결과실행 시간메모리
908060AlfraganusTwo Currencies (JOI23_currencies)C++17
10 / 100
68 ms14696 KiB
#pragma GCC optimize("unroll-loops") #pragma gcc optimize("Ofast") #pragma GCC optimization("Ofast") #pragma optimize(Ofast) #include <bits/stdc++.h> using namespace std; #define int long long #define str string #define fastio ios::sync_with_stdio(0), cin.tie(0); #define fs first #define ss second #define endl '\n' #define all(x) (x).begin(), (x).end() #define len(x) x.size() #define print(a) \ for (auto &x : a) \ cout << x << " "; \ cout << endl; #define printmp(a) \ for (auto &x : a) \ cout << x.fs << " " << x.ss << endl; const int mod = 998244353; vector<vector<pair<int, int>>> tree; vector<int> degree, c; vector<pair<int, int>> p; vector<vector<int>> k; bitset<2001> used; void dfs(int n){ used[n] = 1; for(auto &x : tree[n]){ if(!used[x.fs]){ p[x.fs] = {n, x.ss}; degree[x.fs] = degree[n] + 1; dfs(x.fs); } } } void dfs(int s, int t){ if(s == t) return; if(degree[s] >= degree[t]){ for(auto x : k[p[s].ss]) c.push_back(x); dfs(p[s].fs, t); } else{ for(auto x : k[p[t].ss]) c.push_back(x); dfs(s, p[t].fs); } } void solve(){ int n, m, q; cin >> n >> m >> q; tree.resize(n + 1); for(int i = 0; i < n - 1; i ++){ int u, v; cin >> u >> v; tree[u].push_back({v, i + 1}); tree[v].push_back({u, i + 1}); } k.resize(n); for(int i = 0; i < m; i ++){ int u, v; cin >> u >> v; k[u].push_back(v); } if(n <= 2000 and m <= 2000 and q <= 2000){ degree.resize(n + 1); p.resize(n + 1); dfs(1); while(q --){ int s, t, x, y; cin >> s >> t >> x >> y; dfs(s, t); sort(all(c)); for(int j = 0; j < c.size(); j ++){ if(c[j] <= y) y -= c[j]; else{ x -= c.size() - j; break; } } if(x >= 0) cout << x; else cout << -1; cout << endl; c.clear(); } } else{ } } signed main() { fastio int t = 1; // cin >> t; while (t--) { solve(); cout << endl; } }

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

currencies.cpp:2: warning: ignoring '#pragma gcc optimize' [-Wunknown-pragmas]
    2 | #pragma gcc optimize("Ofast")
      | 
currencies.cpp:3: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    3 | #pragma GCC optimization("Ofast")
      | 
currencies.cpp:4: warning: ignoring '#pragma optimize ' [-Wunknown-pragmas]
    4 | #pragma optimize(Ofast)
      | 
currencies.cpp: In function 'void solve()':
currencies.cpp:85:30: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   85 |             for(int j = 0; j < c.size(); j ++){
      |                            ~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...