QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#69751#5111. Take On MemenocrizWA 1872ms4420kbC++178.0kb2022-12-31 11:21:502022-12-31 11:21:53

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-12-31 11:21:53]
  • 评测
  • 测评结果:WA
  • 用时:1872ms
  • 内存:4420kb
  • [2022-12-31 11:21:50]
  • 提交

answer

//    苔花如米小,也学牡丹开。 
//    Zhikun Wang (nocriz)
//    敢问路在何方 路在脚下

#include <bits/stdc++.h>
using namespace std;
 
using ll = long long; using db = long double; using str = string;
using pi = pair<int,int>; using pl = pair<ll,ll>; using pd = pair<db,db>;
using vi = vector<int>; using vb = vector<bool>; using vl = vector<ll>;
using vd = vector<db>; using vs = vector<str>;
using vpi = vector<pi>; using vpl = vector<pl>; using vpd = vector<pd>;

#define tcT template<class T
#define tcTU tcT, class U
tcT> using V = vector<T>;  tcT, size_t SZ> using AR = array<T,SZ>; tcT> using PR = pair<T,T>;

#define mp make_pair 
#define f first
#define s second
#define sz(x) int((x).size())
#define bg(x) begin(x)
#define all(x) bg(x), end(x)
#define rall(x) x.rbegin(), x.rend() 
#define sor(x) sort(all(x)) 
#define rsz resize
#define ins insert 
#define ft front()
#define bk back()
#define pb push_back
#define eb emplace_back 
#define pf push_front
#define lb lower_bound
#define ub upper_bound

tcT> int lwb(V<T>& a, const T& b) { return int(lb(all(a),b)-bg(a)); }

#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(a,x) for (auto& a: x)

const int MOD = 998244353;
const ll INF = 1e18; // not too close to LLONG_MAX
const db PI = acos((db)-1);
const int dx[4] = {-1, 0, 1, 0}, dy[4] = {0,1,0,-1}; // for every grid problem!!
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count()); 
template<class T> using pqg = priority_queue<T,vector<T>,greater<T>>;

constexpr int pct(int x) { return __builtin_popcount(x); } // # of bits set
constexpr int bits(int x) { return x == 0 ? 0 : 31-__builtin_clz(x); } // floor(log2(x)) 
constexpr int p2(int x) { return 1<<x; }
constexpr int msk2(int x) { return p2(x)-1; }
ll cdiv(ll a, ll b) { return a/b+((a^b)>0&&a%b); } // divide a by b rounded up
ll fdiv(ll a, ll b) { return a/b-((a^b)<0&&a%b); } // divide a by b rounded down
tcT> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
tcT> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
tcTU> T fstTrue(T lo, T hi, U f) { hi ++; assert(lo <= hi); while (lo < hi) { T mid = lo+(hi-lo)/2; f(mid) ? hi = mid : lo = mid+1; } return lo; }
tcTU> T lstTrue(T lo, T hi, U f) { lo --; assert(lo <= hi); while (lo < hi) { T mid = lo+(hi-lo+1)/2; f(mid) ? lo = mid : hi = mid-1; } return lo; }
tcT> void remDup(vector<T>& v) { sort(all(v)); v.erase(unique(all(v)),end(v)); }
tcTU> void erase(T& t, const U& u) { auto it = t.find(u); assert(it != end(t)); t.erase(it); } 
#define tcTUU tcT, class ...U
inline namespace Helpers { tcT, class = void> struct is_iterable : false_type {}; tcT> struct is_iterable<T, void_t<decltype(begin(declval<T>())), decltype(end(declval<T>())) > > : true_type {}; tcT> constexpr bool is_iterable_v = is_iterable<T>::value; tcT, class = void> struct is_readable : false_type {}; tcT> struct is_readable<T, typename std::enable_if_t< is_same_v<decltype(cin >> declval<T&>()), istream&> > > : true_type {}; tcT> constexpr bool is_readable_v = is_readable<T>::value; tcT, class = void> struct is_printable : false_type {}; tcT> struct is_printable<T, typename std::enable_if_t< is_same_v<decltype(cout << declval<T>()), ostream&> > > : true_type {}; tcT> constexpr bool is_printable_v = is_printable<T>::value;}
inline namespace Input { tcT> constexpr bool needs_input_v = !is_readable_v<T> && is_iterable_v<T>; tcTUU> void re(T& t, U&... u); tcTU> void re(pair<T,U>& p); tcT> typename enable_if<is_readable_v<T>,void>::type re(T& x) { cin >> x; } tcT> void re(complex<T>& c) { T a,b; re(a,b); c = {a,b}; } tcT> typename enable_if<needs_input_v<T>,void>::type re(T& i); tcTU> void re(pair<T,U>& p) { re(p.f,p.s); } tcT> typename enable_if<needs_input_v<T>,void>::type re(T& i) { each(x,i) re(x); } tcTUU> void re(T& t, U&... u) { re(t); re(u...); }}
inline namespace ToString {  tcT> constexpr bool needs_output_v = !is_printable_v<T> && is_iterable_v<T>;  tcT> typename enable_if<is_printable_v<T>,str>::type ts(T v) {   stringstream ss; ss << fixed << setprecision(15) << v;   return ss.str(); }  tcT> str bit_vec(T t) {   str res = "{"; F0R(i,sz(t)) res += ts(t[i]);   res += "}"; return res; }  str ts(V<bool> v) { return bit_vec(v); }  template<size_t SZ> str ts(bitset<SZ> b) { return bit_vec(b); }   tcTU> str ts(pair<T,U> p);  tcT> typename enable_if<needs_output_v<T>,str>::type ts(T v);   tcTU> str ts(pair<T,U> p) { return "("+ts(p.f)+", "+ts(p.s)+")"; }  tcT> typename enable_if<is_iterable_v<T>,str>::type ts_sep(T v, str sep) {   bool fst = 1; str res = "";   for (const auto& x: v) {    if (!fst) res += sep;    fst = 0; res += ts(x);   }   return res;  }  tcT> typename enable_if<needs_output_v<T>,str>::type ts(T v) {   return "{"+ts_sep(v,", ")+"}"; }  template<int, class T> typename enable_if<!needs_output_v<T>,vs>::type     ts_lev(const T& v) { return {ts(v)}; }  template<int lev, class T> typename enable_if<needs_output_v<T>,vs>::type     ts_lev(const T& v) {   if (lev == 0 || !sz(v)) return {ts(v)};   vs res;   for (const auto& t: v) {    if (sz(res)) res.bk += ",";    vs tmp = ts_lev<lev-1>(t);    res.ins(end(res),all(tmp));   }   F0R(i,sz(res)) {    str bef = " "; if (i == 0) bef = "{";    res[i] = bef+res[i];   }   res.bk += "}";   return res;  } }
inline namespace Output { template<class T> void pr_sep(ostream& os, str, const T& t) { os << ts(t); } template<class T, class... U> void pr_sep(ostream& os, str sep, const T& t, const U&... u) {pr_sep(os,sep,t); os << sep; pr_sep(os,sep,u...); } template<class ...T> void pr(const T&... t) { pr_sep(cout,"",t...); } void ps() { cout << "\n"; } template<class ...T> void ps(const T&... t) { pr_sep(cout," ",t...); ps(); } template<class ...T> void dbg_out(const T&... t) { pr_sep(cerr," | ",t...); cerr << endl; }void loc_info(int line, str names) { cerr << "Line(" << line << ") -> [" << names << "]: "; } template<int lev, class T> void dbgl_out(const T& t) { cerr << "\n\n" << ts_sep(ts_lev<lev>(t),"\n") << "\n" << endl; } }
#ifdef LOCAL
	#define dbg(...) loc_info(__LINE__,#__VA_ARGS__), dbg_out(__VA_ARGS__)
	#define dbgl(lev,x) loc_info(__LINE__,#x), dbgl_out<lev>(x)
#else 
	#define dbg(...) 0
	#define dbgl(lev,x) 0
#endif
void decrement() {} // subtract one from each
tcTUU> void decrement(T& t, U&... u) { --t; decrement(u...); }
#define ints(...) int __VA_ARGS__; re(__VA_ARGS__);
#define int1(...) ints(__VA_ARGS__); decrement(__VA_ARGS__);

int n;
vi G[10010];
ll x[10010],y[10010];

ll a, b;
ll mv[10010],xm[10010],ym[10010],iv[10010],xi[10010],yi[10010];

ll ans = 0;
void calc(int cn){
	if(!G[cn].size()){
		mv[cn] = iv[cn] = x[cn] * a + y[cn] * b;
		xm[cn] = xi[cn] = x[cn];
		ym[cn] = yi[cn] = y[cn];
		return;
	}
	ll smv = 0, x0 = 0, y0 = 0, snv = 0, x1 = 0, y1 = 0;
	mv[cn] = -1e18;
	iv[cn] = 1e18;
	for(auto ct:G[cn]){
		calc(ct);
		smv+=mv[ct];
		x0+=xm[ct];
		y0+=ym[ct];
		snv+=iv[ct];
		x1+=xi[ct];
		y1+=yi[ct];
		if(mv[ct] + iv[ct] > mv[cn]){
			mv[cn] = mv[ct] + iv[ct];
			xm[cn] = xm[ct] + xi[ct];
			ym[cn] = ym[ct] + yi[ct];
		}
		if(mv[ct] + iv[ct] < iv[cn]){
			iv[cn] = mv[ct] + iv[ct];
			xi[cn] = xm[ct] + xi[ct];
			yi[cn] = ym[ct] + yi[ct];
		}
	}
	mv[cn] -= snv; xm[cn] -= x1; ym[cn] -= y1;
	iv[cn] -= smv; xi[cn] -= x0; yi[cn] -= y0;
	if(cn == 1){
		ans = max(ans,xm[cn]*xm[cn]+ym[cn]*ym[cn]);
		ans = max(ans,xi[cn]*xi[cn]+yi[cn]*yi[cn]);
	}
}


void find(ll x1, ll y1, ll x2, ll y2){
	a = y1 - y2;
	b = x2 - x1;
	calc(1);
	ll x3 = xm[1], y3 = ym[1];
	if(x3*a+y3*b>x1*a+y1*b){
		find(x1, y1 ,x3, y3);
		find(x3, y3, x2, y2);
	}
}

int main() {
	re(n);
	for(int i=1;i<=n;i++){
		ints(cs);
		if(cs == 0){
			re(x[i],y[i]);
		}else{
			int c;
			while(cs--){
				re(c);
				G[i].pb(c);
			}
		}
	}

	a = 1e9; b = 1;
	calc(1);
	ll x1 = xm[1], y1 = ym[1], x2 = xi[1], y2 = yi[1];
	find(x1, y1, x2, y2);
	find(x2, y2, x1, y1);
	ps(ans);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 3708kb

input:

5
4 2 3 4 5
0 2 -2
0 1 3
0 4 -6
0 -18 5

output:

725

result:

ok single line: '725'

Test #2:

score: 0
Accepted
time: 2ms
memory: 3648kb

input:

5
2 2 3
2 4 5
0 1 5
0 -4 -6
0 -1 7

output:

340

result:

ok single line: '340'

Test #3:

score: 0
Accepted
time: 2ms
memory: 3600kb

input:

18
3 4 3 2
2 5 6
3 7 9 8
3 10 11 12
0 4 -1
0 18 49
0 -2 10
2 13 14
0 -5 6
0 5 8
4 15 16 17 18
0 17 3
0 3 -9
0 -7 -1
0 14 -33
0 -23 11
0 11 14
0 2 19

output:

26269

result:

ok single line: '26269'

Test #4:

score: 0
Accepted
time: 1788ms
memory: 4324kb

input:

10000
59 2 171 340 509 678 847 1016 1185 1382 1551 1720 1889 2058 2227 2396 2565 2734 2903 3072 3241 3410 3579 3748 3917 4086 4255 4424 4593 4762 4931 5100 5269 5438 5607 5776 5945 6114 6283 6452 6621 6790 6959 7128 7297 7466 7635 7804 7973 8142 8311 8480 8649 8818 8987 9156 9325 9494 9663 9832
2 3 ...

output:

4893524000116

result:

ok single line: '4893524000116'

Test #5:

score: 0
Accepted
time: 1797ms
memory: 4352kb

input:

10000
37 2 272 542 812 1082 1352 1622 1892 2162 2432 2702 2972 3242 3512 3782 4052 4322 4592 4862 5132 5402 5672 5942 6212 6482 6752 7022 7292 7571 7841 8111 8381 8651 8921 9191 9461 9731
51 3 8 13 18 23 42 47 52 57 62 67 72 77 82 87 92 97 102 107 112 117 122 127 132 137 142 147 152 157 162 167 172 ...

output:

5186192629829

result:

ok single line: '5186192629829'

Test #6:

score: 0
Accepted
time: 1872ms
memory: 4420kb

input:

10000
89 2 114 226 338 450 562 674 786 898 1010 1122 1234 1346 1458 1570 1682 1794 1906 2018 2130 2242 2354 2466 2578 2690 2802 2914 3026 3138 3250 3362 3474 3586 3698 3810 3922 4034 4146 4258 4370 4482 4594 4706 4818 4930 5042 5154 5266 5378 5490 5602 5714 5826 5938 6050 6162 6274 6386 6498 6610 67...

output:

5143217930845

result:

ok single line: '5143217930845'

Test #7:

score: 0
Accepted
time: 2ms
memory: 3772kb

input:

1
0 0 0

output:

0

result:

ok single line: '0'

Test #8:

score: -100
Wrong Answer
time: 2ms
memory: 3708kb

input:

1
0 -1000 0

output:

0

result:

wrong answer 1st lines differ - expected: '1000000', found: '0'