QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#205909 | #7558. Abstract | ucup-team088# | WA | 597ms | 16228kb | C++17 | 8.2kb | 2023-10-07 17:48:43 | 2023-10-07 17:48:44 |
Judging History
answer
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
#include<array>
#include<chrono>
using namespace std;
//#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
//ll mod = 1;
constexpr ll mod = 998244353;
//constexpr ll mod = 1000000007;
const int mod17 = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int>P;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
using ld = double;
typedef pair<ld, ld> LDP;
const ld eps = 1e-10;
const ld pi = acosl(-1.0);
template<typename T>
void chmin(T& a, T b) {
a = min(a, b);
}
template<typename T>
void chmax(T& a, T b) {
a = max(a, b);
}
template<typename T>
vector<T> vmerge(vector<T>& a, vector<T>& b) {
vector<T> res;
int ida = 0, idb = 0;
while (ida < a.size() || idb < b.size()) {
if (idb == b.size()) {
res.push_back(a[ida]); ida++;
}
else if (ida == a.size()) {
res.push_back(b[idb]); idb++;
}
else {
if (a[ida] < b[idb]) {
res.push_back(a[ida]); ida++;
}
else {
res.push_back(b[idb]); idb++;
}
}
}
return res;
}
template<typename T>
void cinarray(vector<T>& v) {
rep(i, v.size())cin >> v[i];
}
template<typename T>
void coutarray(vector<T>& v) {
rep(i, v.size()) {
if (i > 0)cout << " "; cout << v[i];
}
cout << "\n";
}
ll mod_pow(ll x, ll n, ll m = mod) {
if (n < 0) {
ll res = mod_pow(x, -n, m);
return mod_pow(res, m - 2, m);
}
if (abs(x) >= m)x %= m;
if (x < 0)x += m;
//if (x == 0)return 0;
ll res = 1;
while (n) {
if (n & 1)res = res * x % m;
x = x * x % m; n >>= 1;
}
return res;
}
//mod should be <2^31
struct modint {
int n;
modint() :n(0) { ; }
modint(ll m) {
if (m < 0 || mod <= m) {
m %= mod; if (m < 0)m += mod;
}
n = m;
}
operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
bool operator<(modint a, modint b) { return a.n < b.n; }
modint operator+=(modint& a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= (int)mod; return a; }
modint operator-=(modint& a, modint b) { a.n -= b.n; if (a.n < 0)a.n += (int)mod; return a; }
modint operator*=(modint& a, modint b) { a.n = ((ll)a.n * b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, ll n) {
if (n == 0)return modint(1);
modint res = (a * a) ^ (n / 2);
if (n % 2)res = res * a;
return res;
}
ll inv(ll a, ll p) {
return (a == 1 ? 1 : (1 - p * inv(p % a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }
modint operator/=(modint& a, modint b) { a = a / b; return a; }
const int max_n = 1 << 20;
modint fact[max_n], factinv[max_n];
void init_f() {
fact[0] = modint(1);
for (int i = 0; i < max_n - 1; i++) {
fact[i + 1] = fact[i] * modint(i + 1);
}
factinv[max_n - 1] = modint(1) / fact[max_n - 1];
for (int i = max_n - 2; i >= 0; i--) {
factinv[i] = factinv[i + 1] * modint(i + 1);
}
}
modint comb(int a, int b) {
if (a < 0 || b < 0 || a < b)return 0;
return fact[a] * factinv[b] * factinv[a - b];
}
modint combP(int a, int b) {
if (a < 0 || b < 0 || a < b)return 0;
return fact[a] * factinv[a - b];
}
ll gcd(ll a, ll b) {
a = abs(a); b = abs(b);
if (a < b)swap(a, b);
while (b) {
ll r = a % b; a = b; b = r;
}
return a;
}
template<typename T>
void addv(vector<T>& v, int loc, T val) {
if (loc >= v.size())v.resize(loc + 1, 0);
v[loc] += val;
}
/*const int mn = 2000005;
bool isp[mn];
vector<int> ps;
void init() {
fill(isp + 2, isp + mn, true);
for (int i = 2; i < mn; i++) {
if (!isp[i])continue;
ps.push_back(i);
for (int j = 2 * i; j < mn; j += i) {
isp[j] = false;
}
}
}*/
//[,val)
template<typename T>
auto prev_itr(set<T>& st, T val) {
auto res = st.lower_bound(val);
if (res == st.begin())return st.end();
res--; return res;
}
//[val,)
template<typename T>
auto next_itr(set<T>& st, T val) {
auto res = st.lower_bound(val);
return res;
}
using mP = pair<modint, modint>;
mP operator+(mP a, mP b) {
return { a.first + b.first,a.second + b.second };
}
mP operator+=(mP& a, mP b) {
a = a + b; return a;
}
mP operator-(mP a, mP b) {
return { a.first - b.first,a.second - b.second };
}
mP operator-=(mP& a, mP b) {
a = a - b; return a;
}
LP operator+(LP a, LP b) {
return { a.first + b.first,a.second + b.second };
}
LP operator+=(LP& a, LP b) {
a = a + b; return a;
}
LP operator-(LP a, LP b) {
return { a.first - b.first,a.second - b.second };
}
LP operator-=(LP& a, LP b) {
a = a - b; return a;
}
mt19937 mt(time(0));
const string drul = "DRUL";
string senw = "SENW";
//DRUL,or SENW
//int dx[4] = { 1,0,-1,0 };
//int dy[4] = { 0,1,0,-1 };
//------------------------------------
struct graph {
private:
int n;
vector<vector<int>> G, rG;
vector<bool> used;
vector<int> vs;
int mk;
vector<vector<int>> fG;
vector<vector<int>> ori;
vector<int> trans;
public:
graph(int sz) {
n = sz;
G.resize(n);
rG.resize(n);
used.resize(n);
fG.resize(n);
trans.resize(n, -1);
ori.resize(n);
}
void add_edge(int a, int b) {
G[a].push_back(b);
rG[b].push_back(a);
}
void dfs(int v) {
used[v] = true;
rep(i, G[v].size()) {
if (!used[G[v][i]])dfs(G[v][i]);
}
vs.push_back(v);
}
void rdfs(int v, int k) {
used[v] = true;
queue<int> q; q.push(v);
vector<int> c;
while (!q.empty()) {
int id = q.front(); q.pop();
ori[k].push_back(id);
rep(j, rG[id].size()) {
int to = rG[id][j];
if (used[to]) {
if (trans[to] >= 0)c.push_back(trans[to]);
continue;
}
used[to] = true; q.push(to);
}
}
sort(c.begin(), c.end());
int len = unique(c.begin(), c.end()) - c.begin();
rep(i, len) {
fG[c[i]].push_back(k);
}
rep(i, ori[k].size()) {
trans[ori[k][i]] = k;
}
}
void scc() {
fill(used.begin(), used.end(), false);
rep(i, n) {
if (!used[i])dfs(i);
}
fill(used.begin(), used.end(), false);
int k = 0;
per(i, (int)vs.size()) {
if (!used[vs[i]]) {
rdfs(vs[i], k); k++;
}
}
mk = k;
}
vector<int> query() {
vector<int> res;
rep(i, mk) {
res.push_back(ori[i][0]);
}
return res;
}
};
void solve() {
ll sum = 0;
int n, m; cin >> n >> m;
vector<int> a(n);
rep(i, n)cin >> a[i];
graph g(n);
vector<vector<int>> G(n);
vector<vector<int>> rG(n);
rep(i, m) {
int a, b; cin >> a >> b; a--; b--;
G[a].push_back(b);
g.add_edge(a, b);
rG[b].push_back(a);
}
g.scc();
vector<int> ids = g.query();
//coutarray(ids);
int ans = 0;
vector<int> val(n);
val.back() = 1;
sum += a.back();
vector<bool> exipre(n, false);
for (int id : ids) {
for (int to : rG[id]) {
if (exipre[to] || a[to] > 0)exipre[id] = true;
}
}
while (true) {
bool isfin = true;
if (sum)isfin = false;
for (int id : ids) {
if (exipre[id] && val[id] > 0) {
isfin = false; break;
}
}
if (isfin)break;
ans++; sum /= 2;
for (int id : ids) {
if (val[id] == 0)continue;
if (val[id] % 2){
for (int to : rG[id]) {
sum += a[to];
val[to]++;
}
}
val[id] /= 2;
sum += a[id] * val[id];
}
//coutarray(val);
//cout << sum << "\n";
}
cout << ans << "\n";
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
//cout << fixed<<setprecision(12);
//init_f();
//init();
//init2();
//while(true)
//expr();
//int t; cin >> t; rep(i, t)
solve();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 2ms
memory: 11928kb
input:
3 2 1 1 1 1 2 2 3
output:
3
result:
ok 1 number(s): "3"
Test #2:
score: 0
Accepted
time: 2ms
memory: 11924kb
input:
6 8 1 1 4 5 1 4 1 4 1 5 2 3 2 5 3 4 4 5 4 6 5 6
output:
8
result:
ok 1 number(s): "8"
Test #3:
score: 0
Accepted
time: 4ms
memory: 11928kb
input:
5 6 7 2 3 6 6 1 2 1 4 2 3 3 4 3 5 4 5
output:
9
result:
ok 1 number(s): "9"
Test #4:
score: 0
Accepted
time: 397ms
memory: 16148kb
input:
7286 80481 637288250 628935175 588324396 766398783 663989874 865498593 695497968 630237220 19939888 448367842 412696777 111291257 304805809 585852799 58270069 391993802 606944382 827515045 389862501 643981354 160381074 324288921 257053597 980043955 417281046 870855665 360154617 60327683 966755927 55...
output:
7344
result:
ok 1 number(s): "7344"
Test #5:
score: 0
Accepted
time: 111ms
memory: 14916kb
input:
3485 69345 126919335 553087878 429357681 107790917 253972208 821989783 176128117 334722143 34989524 671942525 903789117 265616010 293291124 132216887 707703503 418751992 884191319 759015972 55466567 99122540 354621491 27107365 365748390 577882877 170254553 988104760 599408763 810052334 913007827 481...
output:
3552
result:
ok 1 number(s): "3552"
Test #6:
score: 0
Accepted
time: 179ms
memory: 15328kb
input:
4689 60385 379526147 320297565 290144701 411659092 808895255 349467622 912526797 945207025 147304164 611762485 690455633 593862503 349796612 915342714 685542590 669277310 101349964 538393690 204894013 843271709 963886266 502004930 826860359 607900073 348962474 135953765 54884804 334093983 550287693 ...
output:
4735
result:
ok 1 number(s): "4735"
Test #7:
score: 0
Accepted
time: 30ms
memory: 12944kb
input:
2025 13466 126370676 243460503 613061215 640378899 861853110 677538246 285817021 986777516 15580136 316176404 626530661 279208872 907269727 867851232 311220916 469724204 74428615 32310082 942939721 177419954 762441651 262073944 202700718 559297816 358074717 198943661 440995981 349418644 741410433 25...
output:
2067
result:
ok 1 number(s): "2067"
Test #8:
score: 0
Accepted
time: 0ms
memory: 11968kb
input:
121 199 896493283 602876262 190412813 539005355 361393375 336898107 57573022 860831181 796613695 697555446 474410296 573506583 646847982 775622764 433638751 410211736 706262484 308743162 694033299 787089776 557626422 410409760 666965625 606229683 774588923 213849175 739959306 318954654 193492757 624...
output:
153
result:
ok 1 number(s): "153"
Test #9:
score: 0
Accepted
time: 223ms
memory: 15888kb
input:
5173 82801 972178880 55787886 726219846 273505188 14833165 37678608 275433188 549410719 708739346 1596684 204453484 945870857 502585545 308710857 846757497 570148074 483775449 435833419 921907607 261743006 297037496 320466454 792975799 516106710 589464190 376914168 858666582 446429120 925757959 8940...
output:
5233
result:
ok 1 number(s): "5233"
Test #10:
score: 0
Accepted
time: 168ms
memory: 15212kb
input:
4451 68751 734143298 168118925 474566099 914135738 175189225 854565096 725921855 150734745 33215980 472643707 815730766 973287826 824133531 440222648 918212826 837679353 7350350 167875290 528553053 937486333 615587529 256295189 480035843 489273798 172853737 135811440 968971168 925087779 375176970 33...
output:
4514
result:
ok 1 number(s): "4514"
Test #11:
score: 0
Accepted
time: 65ms
memory: 14364kb
input:
2383 58762 509075060 867612403 21996053 527466121 553589454 671190283 764167183 890805913 862657253 922878788 744689887 170690927 609890819 40416579 350962700 185478150 75096314 104961883 754430815 421417968 778490115 468058225 431868239 303651678 581681467 384545786 339203220 559058549 941951463 37...
output:
2467
result:
ok 1 number(s): "2467"
Test #12:
score: 0
Accepted
time: 52ms
memory: 14424kb
input:
2001 67457 723197687 478813608 232810746 428945491 429136421 648852717 544540978 369132456 184435370 343975895 585223464 502157635 503001231 386021746 670322194 813441457 170390807 934181094 930734781 209174515 312012184 837865721 956809810 794424618 401909501 180498703 669648434 783741686 378051289...
output:
2102
result:
ok 1 number(s): "2102"
Test #13:
score: 0
Accepted
time: 478ms
memory: 15448kb
input:
9489 23514 202036366 696617402 38892756 337095695 965501524 948136577 612864889 980877872 264613206 879049290 604347121 920794549 640708344 587199470 185265444 98746351 581544222 927935481 643077470 812763147 38525503 654269070 256346123 899052544 92441646 264988076 66356031 292735115 922964957 3745...
output:
9521
result:
ok 1 number(s): "9521"
Test #14:
score: 0
Accepted
time: 597ms
memory: 16228kb
input:
9561 54289 98620438 516139680 658256456 902183713 624450302 546644345 93605161 13455288 650974201 859012671 775849200 862051631 839753906 309276811 504053052 106564927 917376230 455638053 499818452 348588006 293037448 892678488 109670419 100714558 133812448 189695864 759580899 825104942 225397418 66...
output:
9603
result:
ok 1 number(s): "9603"
Test #15:
score: 0
Accepted
time: 477ms
memory: 15764kb
input:
8673 41321 713852196 41672085 3578 76498661 193896234 880990702 92363180 297390233 877917509 781447228 559185392 628626089 309281217 479160612 538327677 495012807 230891929 947840408 760224668 4608905 590467332 636974494 563916969 835068689 590302247 655826457 532649798 125153559 521998114 401283582...
output:
8712
result:
ok 1 number(s): "8712"
Test #16:
score: 0
Accepted
time: 15ms
memory: 13300kb
input:
945 29713 352273400 865995982 176653085 727929352 606322564 54353211 560652092 950094104 35932743 672252257 608698156 714904143 464636830 446842133 793178441 165700304 587559973 210748888 475949161 525698243 604063691 220029563 329796511 754927076 272931162 465526795 932512075 597447389 346386244 67...
output:
1035
result:
ok 1 number(s): "1035"
Test #17:
score: -100
Wrong Answer
time: 32ms
memory: 13660kb
input:
1601 43526 328657623 344662164 242182624 662893665 640466981 502913348 345497581 581438973 754099115 328827051 165687194 213281607 767975180 93816219 248298421 561877492 748929658 390895323 957073136 911088737 981351319 138160220 526659627 549050117 99010115 439572276 865895227 821112082 679833882 1...
output:
1693
result:
wrong answer 1st numbers differ - expected: '1692', found: '1693'