QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#355682#4370. Road TimesCrysflyWA 1ms3916kbC++174.5kb2024-03-17 02:02:472024-03-17 02:02:47

Judging History

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

  • [2024-03-17 02:02:47]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3916kb
  • [2024-03-17 02:02:47]
  • 提交

answer

// what is matter? never mind. 
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,sse4,popcnt,abm,mmx,avx,avx2") 
#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(int i=(a);i>=(b);--i)
#define ll long long
//#define int long long
#define ull unsigned long long
#define SZ(x) ((int)((x).size()))
#define ALL(x) (x).begin(),(x).end()
using namespace std;
inline int read()
{
    char c=getchar();int x=0;bool f=0;
    for(;!isdigit(c);c=getchar())f^=!(c^45);
    for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
    if(f)x=-x;return x;
}

const ll P=2305843009213693951;
 
inline ll mul(ll x,ll y){
//	return (__int128)x*y%P;
	ll s=x*y-(ll)((long double)x*y/P)*P;
	if(s<0)return s+P;
	return (s<P?s:s-P);
}
//ll qpow(ll a,ll b){
//	ll c=1;
//	for(;b;b>>=1,a=mul(a,a))if(b&1)c=mul(c,a);
//	return c;
//}
 
#define mod P
struct modint{
	int x;
	modint(int o=0){x=o;}
	modint &operator = (int o){return x=o,*this;}
	modint &operator +=(modint o){return x=x+o.x>=mod?x+o.x-mod:x+o.x,*this;}
	modint &operator -=(modint o){return x=x-o.x<0?x-o.x+mod:x-o.x,*this;}
	modint &operator *=(modint o){return x=mul(x,o.x),*this;}
	modint &operator ^=(int b){
		modint a=*this,c=1;
		for(;b;b>>=1,a*=a)if(b&1)c*=a;
		return x=c.x,*this;
	}
	modint &operator /=(modint o){return *this *=o^=mod-2;}
	friend modint operator +(modint a,modint b){return a+=b;}
	friend modint operator -(modint a,modint b){return a-=b;}
	friend modint operator *(modint a,modint b){return a*=b;}
	friend modint operator /(modint a,modint b){return a/=b;}
	friend modint operator ^(modint a,int b){return a^=b;}
	friend bool operator ==(modint a,int b){return a.x==b;}
	friend bool operator !=(modint a,int b){return a.x!=b;}
	bool operator ! () {return !x;}
	modint operator - () {return x?mod-x:0;}
	bool operator <(const modint&b)const{return x<b.x;}
};
inline modint qpow(modint x,int y){return x^y;}

#define fi first
#define se second
#define pb push_back
#define mkp make_pair
typedef pair<int,int>pii;
typedef vector<int>vi;
 
#define maxn 300005
#define inf 0x3f3f3f3f
#define double long double

int n,id[35][35],f[35][35],g[35][35],cnt;

vector<vector<double>>a;
vector<double>aa;

namespace S{

#define N 2005
typedef double db;
int n,m,id[N];
db a[N][N],res[N],eps=1e-9;
inline int sgn(db x){return x>=-eps&&x<=eps?0:(x<0?-1:1);}

void pivot(int x,int y){
	swap(id[n+x],id[y]);
	db d=-a[x][y];
	For(i,0,n)a[x][i]/=d;
	a[x][y]=-1.0/d;
	For(i,0,m)
		if(i!=x&&sgn(a[i][y])){
			d=a[i][y]; a[i][y]=0;
			For(j,0,n) a[i][j]+=a[x][j]*d;
		}
}

double simplex(vector<vector<double>>aa)
{
	m=aa.size()-1,n=aa[0].size()-1;
	For(i,0,m)For(j,0,n)a[i][j]=aa[i][j];
	For(i,1,m)For(j,1,n)a[i][j]=-a[i][j];
//	cout<<"m,n "<<m<<" "<<n<<"\n";
//	For(i,0,m)For(j,0,n)cout<<a[i][j]<<" \n"[j==n];
	For(i,1,n+m)id[i]=i;
	while(1)
	{
		int u=1,v=0;
		For(i,1,m) if(a[i][0]<a[u][0])u=i;
		if(sgn(a[u][0])>=0)break;
		For(j,1,n) if(sgn(a[u][j])>0 && (!v||id[j]>id[v])) v=j;
		if(!v)puts("Infeasible"),exit(0);
		pivot(u,v);
	}
	while(1)
	{
		int u=0,v=1;
		db mn=1e9;
		For(j,1,n) if(a[0][j]>a[0][v])v=j;
		if(sgn(a[0][v])<=0)break;
		For(i,1,m)
			if(sgn(a[i][v])<0){
				db t=-a[i][0]/a[i][v];
				if(sgn(t-mn)<0 || (sgn(t-mn)==0 && (!u||id[i]>id[u]))) mn=t,u=i;
			}
		if(!u)puts("Unbounded"),exit(0); 
		pivot(u,v);
	}
	return a[0][0];
}

}

vi p;
void path(int u,int v){
	p.clear();
	int dis=f[u][v];
	while(u!=v){
		For(i,1,n)
			if(id[u][i] && g[u][i]+f[i][v]==dis){
				p.pb(id[u][i]);
				dis-=g[u][i];
				u=i; break;
			}
	}
}

signed main()
{
	n=read();
	For(i,1,n)For(j,1,n){
		f[i][j]=read();
		if(f[i][j]==-1)f[i][j]=inf;
		else if(f[i][j])id[i][j]=++cnt;
		g[i][j]=f[i][j];
	}
	For(k,1,n)For(i,1,n)For(j,1,n)f[i][j]=min(f[i][j],f[i][k]+f[k][j]);
	For(i,1,n)For(j,1,n)if(id[i][j]){
		vector<double>t(cnt+1,0);
		t[0]=g[i][j]*2,t[id[i][j]]=1;
		a.pb(t);
		t[0]=-g[i][j],t[id[i][j]]=-1;
		a.pb(t);
	}
	int m=read();
	For(_,1,m){
		int u=read(),v=read(),w=read();
		++u,++v;
		path(u,v);
		for(int i:{1,-1}){
			vector<double>t(cnt+1,0);
			for(auto x:p) t[x]=i;
			t[0]=w*i;
			a.pb(t);
		}
	}
	m=read();
	For(_,1,m){
		int u=read(),v=read();
		++u,++v;
		path(u,v);
		cout<<u-1<<" "<<v-1;
		for(int i:{-1,1}){
			vector<double>t(cnt+1,0);
			for(auto x:p) t[x]=i;
			auto aa=a;
			aa.insert(aa.begin(),t);
			printf(" %.10lf",S::simplex(aa)*i);
		}
		cout<<"\n";
	}
	return 0;
}
/*

*/

详细

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3916kb

input:

3
0 50 -1
55 0 40
-1 40 0
1
0 2 120
3
0 1
1 2
1 0

output:

0 1 0.0000000000 0.0000000000
1 2 0.0000000000 0.0000000000
1 0 0.0000000000 0.0000000000

result:

wrong answer 3rd numbers differ - expected: '50.0000000', found: '0.0000000', error = '1.0000000'