Submission #36106424


Source Code Expand

#include <bits/stdc++.h>
#include <atcoder/modint>
using mint = atcoder::modint998244353;
using namespace std;
typedef long long ll;
typedef __int128 lll;
#define rep(i,a,n) for (ll i=a;i<(ll)n;i++)
ll read(){ll r;scanf("%lld",&r);return r;}
ll C[1010];

// return t0/b0 < t1/b1
bool lt(pair<ll,ll> frac0,pair<ll,ll>frac1){ // less than
  auto [t0,b0]=frac0;
  auto [t1,b1]=frac1;
  assert(b0!=0&&b1!=0);
  if(b0<0){
    t0*=-1;
    b0*=-1;
  }
  if(b1<0){
    t1*=-1;
    b1*=-1;
  }
  return ((lll)t0)*b1 < ((lll)t1)*b0; // 估计不到范围 甩个128吧
}

bool great[1010][1010]; // great[i][j] : cx_i+y_i > cx_j+y_j
int incnt[1010]; // 入度

int main(){
  int n=read();
  int k=read();
  rep(i,0,n)C[i]=read();
  vector<pair<ll,ll>>xy; // {6e5,~36e10}
  rep(i,0,n){
    ll a=0; // fi'(1), alpha, 6e5
    ll b=0; // fi''(1) beta, 6e10
    rep(j,0,6){
      ll v=read();
      a+=v;
      b+=v*(v-1);
    }
    xy.push_back({a,6*a+6*b-a*a-36*C[i]}); // {6e5, ~36e10}
  }
  // c=-infinity
  rep(i,0,n)rep(j,i+1,n){
    auto [xi,yi]=xy[i];
    auto [xj,yj]=xy[j];
    if(xi==xj){ // 不受c影响
      if(yi==yj){ // 完全相等 用index比大小
        great[j][i] = true;
        incnt[i]++;
      }else if(yi<yj){
        great[j][i] = true;
        incnt[i]++;
      }else{
        great[i][j] = true;
        incnt[j]++;
      }
    }else{ // c负无限大且x不想等时 不受y 影响, xi c < xj c  则 xi > xj
      if(xi < xj){ // xic > xjc
        great[i][j] = true;
        incnt[j]++;
      }else{
        great[j][i] = true;
        incnt[i]++;
      }
    }
  }
  ll Sx=0; // 1000 * 6e5 = 6e8
  ll Sy=0; // 1000 * ~36e10 = ~36e13
  auto add=[&](int idx,int t=1){
    Sx+=t*xy[idx].first;
    Sy+=t*xy[idx].second;
  };
  rep(i,0,n) if(incnt[i]<k) add(i);
  ll ans=Sx*Sx+Sy; // 72e13
  vector<pair<pair<ll,ll>,pair<int,int>> > c; // 记录每次翻转的, {{~36e10,12e5},{1e5,1e5}}
  rep(i,0,n)rep(j,i+1,n){
    auto [xi,yi]=xy[i];
    auto [xj,yj]=xy[j]; // c=(yj-yi)/(xi-xj)
    if(xi==xj)continue;
    c.push_back({{yj-yi,xi-xj},{i,j}});
  }
  sort(c.begin(),c.end(),[](auto&v0,auto&v1){return lt(v0.first,v1.first);});
  vector<vector<pair<int,int>>> ijs; // 同斜率合并
  rep(i,0,c.size()){
    if(i==0||lt(c[i-1].first,c[i].first)){
      ijs.push_back({c[i].second});
    }else{
      ijs.back().push_back({c[i].second});
    }
  }
  for(auto ij:ijs){
    for(auto [i,j]:ij){
      if(great[j][i]) swap(i,j); // assert(i > j)
      great[i][j]=false; // 可以省略great的修改, 因为只有incnt真的参与计算, 之后swap也不会再有i,j
      if(incnt[j]--==k) add(j); // k => k-1 原来没j 现在有j
      great[j][i]=true;
      if(++incnt[i]==k) add(i,-1); // k-1 => k 原来有i 现在无i
    }
    ans=max(ans,Sx*Sx+Sy);
  }
  printf("%d\n",(mint(ans)/36).val());
  return 0;
}

Submission Info

Submission Time
Task Ex - Dice Sum 2
User cromarmot
Language C++ (GCC 9.2.1)
Score 600
Code Size 2831 Byte
Status AC
Exec Time 188 ms
Memory 43464 KiB

Compile Error

./Main.cpp: In function ‘ll read()’:
./Main.cpp:8:21: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
    8 | ll read(){ll r;scanf("%lld",&r);return r;}
      |                ~~~~~^~~~~~~~~~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 600 / 600
Status
AC × 2
AC × 78
Set Name Test Cases
Sample 00_sample_01.txt, 00_sample_02.txt
All 00_sample_01.txt, 00_sample_02.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 02_random2_01.txt, 02_random2_02.txt, 02_random2_03.txt, 02_random2_04.txt, 02_random2_05.txt, 02_random2_06.txt, 02_random2_07.txt, 02_random2_08.txt, 02_random2_09.txt, 02_random2_10.txt, 03_random3_01.txt, 03_random3_02.txt, 03_random3_03.txt, 03_random3_04.txt, 03_random3_05.txt, 03_random3_06.txt, 03_random3_07.txt, 03_random3_08.txt, 03_random3_09.txt, 03_random3_10.txt, 04_random4_01.txt, 04_random4_02.txt, 04_random4_03.txt, 04_random4_04.txt, 04_random4_05.txt, 04_random4_06.txt, 04_random4_07.txt, 04_random4_08.txt, 04_random4_09.txt, 04_random4_10.txt, 05_max_01.txt, 05_max_02.txt, 05_max_03.txt, 05_max_04.txt, 05_max_05.txt, 05_max_06.txt, 05_max_07.txt, 05_max_08.txt, 05_max_09.txt, 05_max_10.txt, 06_ans_negative_01.txt, 06_ans_negative_02.txt, 06_ans_negative_03.txt, 06_ans_negative_04.txt, 06_ans_negative_05.txt, 06_ans_negative_06.txt, 06_ans_negative_07.txt, 06_ans_negative_08.txt, 06_ans_negative_09.txt, 06_ans_negative_10.txt, 07_hack1_01.txt, 07_hack1_02.txt, 07_hack1_03.txt, 07_hack1_04.txt, 07_hack1_05.txt, 07_hack1_06.txt, 07_hack1_07.txt, 07_hack1_08.txt, 07_hack1_09.txt, 07_hack1_10.txt, 08_hack_climbing_01.txt, 08_hack_climbing_02.txt, 08_hack_climbing_03.txt, 08_hack_climbing_04.txt, 08_hack_climbing_05.txt, 09_hack_sort_01.txt
Case Name Status Exec Time Memory
00_sample_01.txt AC 7 ms 3804 KiB
00_sample_02.txt AC 2 ms 3820 KiB
01_random_01.txt AC 47 ms 13132 KiB
01_random_02.txt AC 67 ms 18572 KiB
01_random_03.txt AC 76 ms 20688 KiB
01_random_04.txt AC 91 ms 23472 KiB
01_random_05.txt AC 76 ms 20216 KiB
01_random_06.txt AC 109 ms 31480 KiB
01_random_07.txt AC 48 ms 13132 KiB
01_random_08.txt AC 133 ms 35808 KiB
01_random_09.txt AC 15 ms 5372 KiB
01_random_10.txt AC 32 ms 10124 KiB
02_random2_01.txt AC 174 ms 39240 KiB
02_random2_02.txt AC 174 ms 39128 KiB
02_random2_03.txt AC 177 ms 38900 KiB
02_random2_04.txt AC 173 ms 38972 KiB
02_random2_05.txt AC 178 ms 38888 KiB
02_random2_06.txt AC 143 ms 35168 KiB
02_random2_07.txt AC 113 ms 23872 KiB
02_random2_08.txt AC 25 ms 7712 KiB
02_random2_09.txt AC 23 ms 7468 KiB
02_random2_10.txt AC 38 ms 10388 KiB
03_random3_01.txt AC 183 ms 42816 KiB
03_random3_02.txt AC 186 ms 42816 KiB
03_random3_03.txt AC 181 ms 42848 KiB
03_random3_04.txt AC 180 ms 42816 KiB
03_random3_05.txt AC 181 ms 42820 KiB
03_random3_06.txt AC 27 ms 8108 KiB
03_random3_07.txt AC 8 ms 4360 KiB
03_random3_08.txt AC 65 ms 17320 KiB
03_random3_09.txt AC 2 ms 3804 KiB
03_random3_10.txt AC 179 ms 42120 KiB
04_random4_01.txt AC 179 ms 43256 KiB
04_random4_02.txt AC 182 ms 43384 KiB
04_random4_03.txt AC 181 ms 43372 KiB
04_random4_04.txt AC 183 ms 43464 KiB
04_random4_05.txt AC 183 ms 43348 KiB
04_random4_06.txt AC 110 ms 31776 KiB
04_random4_07.txt AC 166 ms 39892 KiB
04_random4_08.txt AC 83 ms 21584 KiB
04_random4_09.txt AC 120 ms 32956 KiB
04_random4_10.txt AC 139 ms 36264 KiB
05_max_01.txt AC 10 ms 4772 KiB
05_max_02.txt AC 7 ms 4644 KiB
05_max_03.txt AC 185 ms 43256 KiB
05_max_04.txt AC 182 ms 43456 KiB
05_max_05.txt AC 179 ms 43464 KiB
05_max_06.txt AC 183 ms 43460 KiB
05_max_07.txt AC 184 ms 43296 KiB
05_max_08.txt AC 181 ms 43372 KiB
05_max_09.txt AC 182 ms 43384 KiB
05_max_10.txt AC 188 ms 43296 KiB
06_ans_negative_01.txt AC 173 ms 40088 KiB
06_ans_negative_02.txt AC 174 ms 39956 KiB
06_ans_negative_03.txt AC 170 ms 39920 KiB
06_ans_negative_04.txt AC 170 ms 39776 KiB
06_ans_negative_05.txt AC 180 ms 39944 KiB
06_ans_negative_06.txt AC 175 ms 39924 KiB
06_ans_negative_07.txt AC 174 ms 39824 KiB
06_ans_negative_08.txt AC 176 ms 39932 KiB
06_ans_negative_09.txt AC 172 ms 40040 KiB
06_ans_negative_10.txt AC 173 ms 39912 KiB
07_hack1_01.txt AC 139 ms 22516 KiB
07_hack1_02.txt AC 135 ms 22344 KiB
07_hack1_03.txt AC 135 ms 22496 KiB
07_hack1_04.txt AC 139 ms 22516 KiB
07_hack1_05.txt AC 136 ms 22452 KiB
07_hack1_06.txt AC 134 ms 22608 KiB
07_hack1_07.txt AC 134 ms 22440 KiB
07_hack1_08.txt AC 135 ms 22496 KiB
07_hack1_09.txt AC 135 ms 22600 KiB
07_hack1_10.txt AC 138 ms 22620 KiB
08_hack_climbing_01.txt AC 46 ms 11932 KiB
08_hack_climbing_02.txt AC 45 ms 12044 KiB
08_hack_climbing_03.txt AC 46 ms 11988 KiB
08_hack_climbing_04.txt AC 47 ms 12032 KiB
08_hack_climbing_05.txt AC 47 ms 12032 KiB
09_hack_sort_01.txt AC 3 ms 3768 KiB