QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#215060 | #7558. Abstract | TheOneYouWant# | RE | 0ms | 3840kb | C++17 | 3.4kb | 2023-10-15 02:48:22 | 2023-10-15 02:48:22 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
#define ln '\n'
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef pair<int, int> pii;
typedef vector<int> vi;
const int INF = 1e9+7;
const int bignumlen=200;
const int base=100000000;
struct bignum{
int len;
int data[bignumlen];
int &operator [](int x){ return(data[x]);}
const int &operator [](int x)const { return(data[x]);}
bignum (){
memset(data,0,sizeof(data));
len=0;
}
int check (const bignum &a,const bignum &b){
if(a.len>b.len)return(0);
if(b.len>a.len)return(1);
for(int i=a.len;i>=1;--i){
if(a.data[i]<b.data[i])return(1);
if(b.data[i]<a.data[i])return(0);
}
return 2;
}
bool operator < (const bignum &b){ return(check(*this,b)==1);}
bool operator <=(const bignum &b){ return(check(*this,b)>=1);}
bignum operator=(const bignum &x){
for(int i=x.len+1;i<=len;++i)data[i]=0;
for(int i=1;i<=x.len;++i)data[i]=x.data[i];
len=x.len;
return *this;
}
bignum operator=(int x){
for(int i=len;i>=0;--i)data[i]=0;
len=0;
while(x){
data[++len]=x%base;
x/=base;
}
return *this;
}
bignum(int x){
memset(data,0,sizeof(data));
len=0;
(*this)=x;
}
bignum operator *(const bignum &b){
int i,j;
bignum tmp;
for(i=1;i<=len;++i)if(data[i]!=0)
for(j=1;j<=b.len;++j)if(b.data[j]!=0){
tmp.data[i+j-1]+=data[i]*b.data[j];
tmp.data[i+j]+=tmp.data[i+j-1]/base;
tmp.data[i+j-1]%=base;
}
tmp.len=len+b.len-1;
while(tmp.data[tmp.len+1])tmp.len++;
return tmp;
}
bignum operator *(int x){
int i;
bignum tmp;
for(i=1;i<=len;++i)tmp[i]=data[i]*x;
tmp.len=len;
for(i=1;i<=len;++i){
tmp[i+1]+=tmp[i]/base,tmp[i]%=base;
if(tmp[i+1]&&i+1>tmp.len)tmp.len++;
}
return tmp;
}
bignum operator +(const bignum &b){
bignum tmp;
int i,l=max(len,b.len);
for(i=1;i<=l;++i)tmp[i]=data[i]+b[i];
for(i=1;i<=l;++i)tmp[i+1]+=tmp[i]/base,tmp[i]%=base;
tmp.len=l;
if(tmp[tmp.len+1])tmp.len++;
return tmp;
}
bignum operator +=(const bignum &b){return *this=(*this+b);}
bignum operator *=(const bignum &b){return *this=(*this*b);}
bignum operator *=(int x) {return( *this=(*this *x));}
};
vi topoSort(const vector<vi>& gr) {
vi indeg(sz(gr)), ret;
for (auto& li : gr) for (int x : li) indeg[x]++;
queue<int> q; // use priority_queue for lexic. largest ans.
rep(i,0,sz(gr)) if (indeg[i] == 0) q.push(i);
while (!q.empty()) {
int i = q.front(); // top() for priority queue
ret.push_back(i);
q.pop();
for (int x : gr[i])
if (--indeg[x] == 0) q.push(x);
}
return ret;
}
int n, m;
vi a;
vector<vi> g;
vector<bignum> c;
bignum p(0);
int32_t main() {
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n >> m;
a.resize(n);
g.resize(n);
c.resize(n);
rep(i,0, n)
cin>>a[i];
rep(i, 0, m) {
int a, b;
cin >> a >> b;
a--; b--;
g[a].push_back(b);
}
vi v = topoSort(g);
c[v[n-1]] = bignum(1);
for(int i = n-2; i >= 0; i--) {
c[v[i]] = bignum(0);
for(int u : g[v[i]])
c[v[i]] += (c[u] * 2);
}
rep(i, 0, n)
p += c[i]*a[i];
bignum cmp(1);
int pw = 0;
while(cmp <= p) {
pw++;
cmp *= 2;
}
cout << pw << ln;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3840kb
input:
3 2 1 1 1 1 2 2 3
output:
3
result:
ok 1 number(s): "3"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3620kb
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: 0ms
memory: 3632kb
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: -100
Runtime Error
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...