NC213131. Determinant
描述
输入描述
The input consists of several test cases terminated by end-of-file.
The first line of each test case contains two integers n and x. The second line contains n integers . The third line contains n integers .
*
*
* The sum of n does not exceed .
输出描述
For each test case, print an integer which denotes the result.
示例1
输入:
2 1 0 0 0 0 2 1 1000000000 1000000000 1000000000 1000000000 3 2 2 3 3 2 3 3
输出:
1 99 96
C++(clang++11) 解法, 执行用时: 680ms, 内存消耗: 1412K, 提交时间: 2020-11-01 10:52:43
#include<iostream> using namespace std; const long long mod=1e9+7; #define ll long long ll a[200000]; int main() { ll n,x; while(cin>>n>>x) { for(ll i=1;i<=n;i++) { cin>>a[i]; } ll sum=x,k; for(ll i=1;i<=n;i++) { cin>>k; sum=(sum+k*a[i])%mod; } for(ll i=1;i<n;i++) { sum=(sum*x)%mod; } cout<<sum<<endl; } return 0; }
Python3(3.9) 解法, 执行用时: 1040ms, 内存消耗: 22340K, 提交时间: 2020-11-11 21:54:15
def gt(): return list(map(int,input().split())) M=1000000007 while 1: try: n,x = gt() except: break; a = gt() b = gt() ans = pow(x,n-1,M) tmp = x for i in range(n): tmp += a[i]*b[i] tmp %= M ans = ans*tmp%M print(ans)
pypy3(pypy3.6.1) 解法, 执行用时: 1073ms, 内存消耗: 62280K, 提交时间: 2020-12-30 20:35:58
MODN=int(1e9+7) while True: try: n,x=list(map(int,input().split())) except: break a=list(map(int,input().split())) b=list(map(int,input().split())) up=0 for i in range(n): up+=a[i]*b[i] up%=MODN print((pow(x,n,MODN)+pow(x,n-1,MODN)*up)%MODN)