QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#215067#7558. Abstractb2ogeymanWA 0ms3868kbC++173.3kb2023-10-15 02:53:052023-10-15 02:53:06

Judging History

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

  • [2023-10-15 02:53:06]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3868kb
  • [2023-10-15 02:53:05]
  • 提交

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=400;
const int base=(1LL << 31);

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;
	rep(i,0,sz(gr)) if (indeg[i] == 0) q.push(i);
	while (!q.empty()) {
		int i = q.front();
		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;
}

詳細信息

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: -100
Wrong Answer
time: 0ms
memory: 3868kb

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:

7

result:

wrong answer 1st numbers differ - expected: '8', found: '7'