結果

問題 No.1201 お菓子配り-4
ユーザー 👑 tute7627tute7627
提出日時 2020-08-28 22:18:06
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3,241 ms / 4,000 ms
コード長 742 bytes
コンパイル時間 2,062 ms
コンパイル使用メモリ 196,144 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-26 13:17:34
合計ジャッジ時間 20,594 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 51 ms
5,248 KB
testcase_01 AC 669 ms
5,376 KB
testcase_02 AC 971 ms
5,376 KB
testcase_03 AC 471 ms
5,376 KB
testcase_04 AC 231 ms
5,376 KB
testcase_05 AC 576 ms
5,376 KB
testcase_06 AC 89 ms
5,376 KB
testcase_07 AC 259 ms
5,376 KB
testcase_08 AC 726 ms
5,376 KB
testcase_09 AC 529 ms
5,376 KB
testcase_10 AC 6 ms
5,376 KB
testcase_11 AC 138 ms
5,376 KB
testcase_12 AC 1,097 ms
5,376 KB
testcase_13 AC 32 ms
5,376 KB
testcase_14 AC 16 ms
5,376 KB
testcase_15 AC 865 ms
5,376 KB
testcase_16 AC 262 ms
5,376 KB
testcase_17 AC 338 ms
5,376 KB
testcase_18 AC 56 ms
5,376 KB
testcase_19 AC 53 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 1 ms
5,376 KB
testcase_27 AC 1 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
testcase_29 AC 2 ms
5,376 KB
testcase_30 AC 1,390 ms
5,376 KB
testcase_31 AC 1,389 ms
5,376 KB
testcase_32 AC 1,382 ms
5,376 KB
testcase_33 AC 1,379 ms
5,376 KB
testcase_34 AC 1,379 ms
5,376 KB
testcase_35 AC 3,241 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using lint = long long;

int64_t f(int a, int b, int c, int n) {
    if (n < 0 || a == 0) return 0;
    if (a >= c || b >= c) 
        return (a / c) * (1LL * n * (n + 1) / 2) + 1LL * (b / c) * (n + 1) + f(a % c, b % c, c, n);
    int64_t m = (1LL * a * n + b) / c;
    return 1LL * n * m - f(c, c - b - 1, a, m - 1);
}

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  int n,m;cin>>n>>m;
  vector<int>a(n),b(m);
  const long long mod=1e9+7;
  for(int i=0;i<n;i++)cin>>a[i];
  for(int i=0;i<m;i++)cin>>b[i];
  long long ret=0;
  for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
      long long add=f(a[i],0,b[j],b[j]);
      ret=(ret+add*2)%mod;
    }
  }
  cout<<ret<<endl;
}
0