QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#626026 | #9349. Exchanging Gifts | ThisTime | Compile Error | / | / | C++20 | 2.8kb | 2024-10-09 22:28:44 | 2024-10-09 22:28:44 |
Judging History
answer
#include<bits/stdc++.h>
#define deg(a) cout << #a << '=' << a << "\n"
#define all(a) a.begin(),a.end()
#define lowbit(x) ((x)&(-x))
#define find1(x) (__builtin_popcount(x))
#define pll pair<int,int>
// #define int long long
#define endl '\n'
#define ff first
#define ss second
#define lc p<<1
#define rc p<<1|1
using namespace std;
using ll = long long;
const int N = 2e6+10;
const int M = 1e6+10;
const int mod1 = 998244353;
const int mod2 = 1e9+7;
const int inf = 0x3f3f3f3f3f3f3f;
const double eps = 1e-12;
int op[N];
std::vector<int> G[N];
int din[N] = {0};
int cnt[N] = {0};
map<int,int>F[N];
map<int,int>mp;
inline char nc() {
static char buf[1000000], *p1 = buf, *p2 = buf;
return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2) ? EOF : *p1++;
}
template <typename _Tp> inline void read(_Tp&sum) {
char ch = nc(); sum = 0;
while (!(ch >= '0'&&ch <= '9')) ch = nc();
while (ch >= '0'&&ch <= '9') sum = (sum << 3) + (sum << 1) + (ch - 48), ch = nc();
}
void solve(){
int n;
read(n);
mp.clear();
for(int i = 1 ; i <= n ; i++) {
G[i].clear();
F[i].clear();
din[i] = 0;
cnt[i] = 0;
}
for(int i = 1 ; i <= n ; i++) {
read(op[i]);
// cin >> op[i];
if(op[i] == 1) {
int k;
read(k);
// cin >> k;
for(int j = 1 ; j <= k ; j++) {
int x;
read(x);
// cin >> x;
F[i][x]++;
}
}else if(op[i] == 2) {
int x,y;
// cin >> x >> y;
read(x);
read(y);
G[i].push_back(x);
G[i].push_back(y);
din[x]++;
din[y]++;
}
}
queue<int>q;
for(int i = 1 ; i <= n ; i++) {
if(din[i] == 0) {
q.push(i);
if(i == n) cnt[n] = 1;
}
}
while(q.size()) {
int u = q.front();
q.pop();
for(auto v : G[u]) {
din[v]--;
cnt[v] += cnt[u];
if(din[v] == 0) {
q.push(v);
}
}
}
long long sum = 0;
long long maxx = 0;
for(int i = 1 ; i <= n ; i++) {
if(op[i] == 2) continue;
for(auto [x,y] : F[i]) {
mp[x] += cnt[i] * y;
sum += cnt[i] * y;
maxx = max(maxx,mp[x]);
}
}
long long ans = 0;
int res = sum - maxx;
if(maxx * 2 <= sum) {
ans = sum;
}else {
ans = res * 2;
}
printf("%lld\n", ans);
}
signed main()
{
// cin.tie(nullptr);
// ios::sync_with_stdio(false);
int kk = 1;
cin >> kk;
//cin.get();
while(kk--) solve();
return 0;
}
详细
answer.code:19:17: warning: overflow in conversion from ‘long int’ to ‘int’ changes value from ‘17802464409370431’ to ‘1061109567’ [-Woverflow] 19 | const int inf = 0x3f3f3f3f3f3f3f; | ^~~~~~~~~~~~~~~~ answer.code: In function ‘void solve()’: answer.code:95:23: error: no matching function for call to ‘max(long long int&, std::map<int, int>::mapped_type&)’ 95 | maxx = max(maxx,mp[x]); | ~~~^~~~~~~~~~~~ In file included from /usr/include/c++/13/algorithm:60, from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:51, from answer.code:1: /usr/include/c++/13/bits/stl_algobase.h:257:5: note: candidate: ‘template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)’ 257 | max(const _Tp& __a, const _Tp& __b) | ^~~ /usr/include/c++/13/bits/stl_algobase.h:257:5: note: template argument deduction/substitution failed: answer.code:95:23: note: deduced conflicting types for parameter ‘const _Tp’ (‘long long int’ and ‘std::map<int, int>::mapped_type’ {aka ‘int’}) 95 | maxx = max(maxx,mp[x]); | ~~~^~~~~~~~~~~~ /usr/include/c++/13/bits/stl_algobase.h:303:5: note: candidate: ‘template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)’ 303 | max(const _Tp& __a, const _Tp& __b, _Compare __comp) | ^~~ /usr/include/c++/13/bits/stl_algobase.h:303:5: note: template argument deduction/substitution failed: answer.code:95:23: note: deduced conflicting types for parameter ‘const _Tp’ (‘long long int’ and ‘std::map<int, int>::mapped_type’ {aka ‘int’}) 95 | maxx = max(maxx,mp[x]); | ~~~^~~~~~~~~~~~ In file included from /usr/include/c++/13/algorithm:61: /usr/include/c++/13/bits/stl_algo.h:5795:5: note: candidate: ‘template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)’ 5795 | max(initializer_list<_Tp> __l) | ^~~ /usr/include/c++/13/bits/stl_algo.h:5795:5: note: template argument deduction/substitution failed: answer.code:95:23: note: mismatched types ‘std::initializer_list<_Tp>’ and ‘long long int’ 95 | maxx = max(maxx,mp[x]); | ~~~^~~~~~~~~~~~ /usr/include/c++/13/bits/stl_algo.h:5805:5: note: candidate: ‘template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)’ 5805 | max(initializer_list<_Tp> __l, _Compare __comp) | ^~~ /usr/include/c++/13/bits/stl_algo.h:5805:5: note: template argument deduction/substitution failed: answer.code:95:23: note: mismatched types ‘std::initializer_list<_Tp>’ and ‘long long int’ 95 | maxx = max(maxx,mp[x]); | ~~~^~~~~~~~~~~~