QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#749372#2562. Fake Plastic Trees 2arvindr9Compile Error//C++204.4kb2024-11-14 23:56:282024-11-14 23:56:29

Judging History

你现在查看的是最新测评结果

  • [2024-11-14 23:56:29]
  • 评测
  • [2024-11-14 23:56:28]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#define DEBUG(...) debug(#__VA_ARGS__, __VA_ARGS__)
#else
#define DEBUG(...) 6
#endif
 
template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) {return os << "(" << p.first << ", " << p.second << ")";}
template<typename C, typename T = decay<decltype(*begin(declval<C>()))>, typename enable_if<!is_same<C, string>::value>::type* = nullptr>
ostream& operator << (ostream &os, const C &c) {bool f = true; os << "["; for (const auto &x : c) {if (!f) os << ", "; f = false; os << x;} return os << "]";}
template<typename T> void debug(string s, T x) {cerr << "\033[1;35m" << s << "\033[0;32m = \033[33m" << x << "\033[0m\n";}
template<typename T, typename... Args> void debug(string s, T x, Args... args) {for (int i=0, b=0; i<(int)s.size(); i++) if (s[i] == '(' || s[i] == '{') b++; else
if (s[i] == ')' || s[i] == '}') b--; else if (s[i] == ',' && b == 0) {cerr << "\033[1;35m" << s.substr(0, i) << "\033[0;32m = \033[33m" << x << "\033[31m | "; debug(s.substr(s.find_first_not_of(' ', i + 1)), args...); break;}}

typedef int int2;
#define int __int128
#define pi pair<int, int>
#define vi vector<int>
#define vii vector<vector<int>>
#define vpi vector<pi>
#define lep(i,l,r) for(int i=l;i<=r;++i)
#define rep(i,r,l) for(int i=r;i>=l;--i)
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define f first
#define s second

int t;

const int maxn = 1005;
const int maxk = 51;
set<pi> dp[maxn]; // (num components, total overflow)

int2 main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> t;
    while (t--) {
        int n, k, l, r;
        {
            long long a, b, c, d;
            cin >> a >> b >> c >> d;
            n = a;
            k = b;
            l = c;
            r = d;
        }

        vector<int> a(n+1);
        lep(i,1,n) {
            long long x;
            cin >> x;
            a[i] = x;
        }
        vector<vector<int>> adj(n+1);
        lep(i,1,n-1) {
            long long u,v;
            cin >> u >> v;
            adj[u].pb(v);
            adj[v].pb(u);
        }

        vector<int> sub(n+1);

        auto dfs1 = [&](auto &self, int u, int p) -> void {
            int val = a[u];
            for (int v: adj[u]) {
                if (v != p) {
                    self(self,v,u);
                    val += sub[v];
                }
            }
            sub[u] = val;
            // assert(sub[u] >= 0);
        };

        dfs1(dfs1,1,0);

        auto dfs2 = [&](auto &self, int u, int p) -> void {
            set<pi> curdp = {mp(0LL,0LL)};
            for (int v: adj[u]) {
                if (v != p) {
                    self(self,v,u);
                    set<pi> nextdp;
                    for (auto [nc, oc]: curdp) {
                        for (auto [nv, ov]: dp[v]) {
                            if (nc + nv <= k) {
                                nextdp.insert({nc+nv,oc+ov});
                            }
                        } 
                    }
                    swap(curdp, nextdp);
                }
            }
            // DEBUG(u,curdp);
            for (auto [nc, oc]: curdp) {
                // remaining stuff is <= R -> might be relevant for future components
                int gap = sub[u] - l * nc - oc;
                if (gap <= r) {
                    dp[u].insert({nc,oc});
                }
                // check if you're allowed to make a new component
                if (l <= gap and gap <= r) {
                    if (nc == k+1) continue;
                    dp[u].insert({nc+1, sub[u] - (nc+1)*l});
                }
            }
        };

        dfs2(dfs2,1,0);

        // DEBUG(dp[1]);
        // DEBUG(dp[2]);
        // DEBUG(dp[3]);
        // DEBUG(dp[4]);

        lep(i,1,k+1) {
            int target_overflow = sub[1] - i * l;
            // DEBUG(i,target_overflow);
            if (dp[1].count({i,target_overflow})) {
                cout << 1;
            } else {
                cout << 0;
            } 
        }
        cout << "\n";

        lep(i,1,n) {
            dp[i].clear();
        }
    }

    
} 

/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
	* DON'T GET STUCK ON ONE APPROACH
*/

详细

answer.code: In function ‘int2 main()’:
answer.code:41:9: error: no match for ‘operator>>’ (operand types are ‘std::istream’ {aka ‘std::basic_istream<char>’} and ‘__int128’)
   41 |     cin >> t;
      |     ~~~ ^~ ~
      |     |      |
      |     |      __int128
      |     std::istream {aka std::basic_istream<char>}
In file included from /usr/include/c++/13/sstream:40,
                 from /usr/include/c++/13/complex:45,
                 from /usr/include/c++/13/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:127,
                 from answer.code:1:
/usr/include/c++/13/istream:325:7: note: candidate: ‘std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(void*&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]’ (near match)
  325 |       operator>>(void*& __p)
      |       ^~~~~~~~
/usr/include/c++/13/istream:325:7: note:   conversion of argument 1 would be ill-formed:
answer.code:41:12: error: invalid conversion from ‘__int128’ to ‘void*’ [-fpermissive]
   41 |     cin >> t;
      |            ^
      |            |
      |            __int128
answer.code:41:12: error: cannot bind rvalue ‘(void*)((long int)t)’ to ‘void*&’
/usr/include/c++/13/istream:224:7: note: candidate: ‘std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(long double&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]’ (near match)
  224 |       operator>>(long double& __f)
      |       ^~~~~~~~
/usr/include/c++/13/istream:224:7: note:   conversion of argument 1 would be ill-formed:
answer.code:41:12: error: cannot bind non-const lvalue reference of type ‘long double&’ to a value of type ‘__int128’
   41 |     cin >> t;
      |            ^
/usr/include/c++/13/istream:220:7: note: candidate: ‘std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(double&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]’ (near match)
  220 |       operator>>(double& __f)
      |       ^~~~~~~~
/usr/include/c++/13/istream:220:7: note:   conversion of argument 1 would be ill-formed:
answer.code:41:12: error: cannot bind non-const lvalue reference of type ‘double&’ to a value of type ‘__int128’
   41 |     cin >> t;
      |            ^
/usr/include/c++/13/istream:216:7: note: candidate: ‘std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(float&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]’ (near match)
  216 |       operator>>(float& __f)
      |       ^~~~~~~~
/usr/include/c++/13/istream:216:7: note:   conversion of argument 1 would be ill-formed:
answer.code:41:12: error: cannot bind non-const lvalue reference of type ‘float&’ to a value of type ‘__int128’
   41 |     cin >> t;
      |            ^
/usr/include/c++/13/istream:201:7: note: candidate: ‘std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(long long unsigned int&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]’ (near match)
  201 |       operator>>(unsigned long long& __n)
      |       ^~~~~~~~
/usr/include/c++/13/istream:201:7: note:   conversion of argument 1 would be ill-formed:
answer.code:41:12: error: cannot bind non-const lvalue reference of type ‘long long unsigned int&’ to a value of type ‘__int128’
   41 |     cin >> t;
      |            ^
/usr/include/c++/13/istream:197:7: note: candidate: ‘std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(long long int&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]’ (near match)
  197 |       operator>>(long long& __n)
      |       ^~~~~~~~
/usr/include/c++/13/istream:197:7: note:   conversion of argument 1 would be ill-formed:
answer.code:41:12: error: cannot bind non-const lvalue reference of type ‘long long int&’ to a value of type ‘__int128’
   41 |     cin >> t;
      |            ^
/usr/include/c++/13/istream:192:7: note: candidate: ‘std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(long unsigned int&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]’ (near match)
  192 |       operator>>(unsigned long& __n)
      |       ^~~~~~~~
/usr/include/c++/13/istream:192:7: note:   conversion of argument 1 would be ill-formed:
answer.code:41:12: error: cannot bind non-const lvalue reference of type ‘long unsigned int&’ to a value of type ‘__int128’
   41 |     cin >> t;
      |            ^
/usr/include/c++/13/istream:188:7: note: candidate: ‘std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_Char...