結果

問題 No.1060 素敵な宝箱
ユーザー beetbeet
提出日時 2020-05-22 21:57:05
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,813 bytes
コンパイル時間 5,956 ms
コンパイル使用メモリ 247,364 KB
最終ジャッジ日時 2025-01-10 14:42:24
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:67:18: error: reference to 'identity' is ambiguous
   67 |   auto zs=zip(sc,identity(n));
      |                  ^~~~~~~~
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.4.0/include/c++/12/bits/iterator_concepts.h:38,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.4.0/include/c++/12/bits/stl_iterator_base_types.h:71,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.4.0/include/c++/12/bits/stl_algobase.h:65,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.4.0/include/c++/12/bits/specfun.h:45,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.4.0/include/c++/12/cmath:1935,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.4.0/include/c++/12/x86_64-pc-linux-gnu/bits/stdc++.h:41,
                 from main.cpp:1:
/home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.4.0/include/c++/12/bits/ranges_cmp.h:47:10: note: candidates are: 'struct std::identity'
   47 |   struct identity
      |          ^~~~~~~~
main.cpp:38:13: note:                 'std::vector<long long int> identity(Int)'
   38 | vector<Int> identity(Int n){
      |             ^~~~~~~~

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
using Int = long long;
const char newl = '\n';


template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}


template<typename ...Ts>
decltype(auto) zip(vector<Ts>... args){
  vector<decltype(make_tuple(args[0]...))> res;
  Int n=min({args.size()...});
  res.reserve(n);
  for(Int i=0;i<n;i++) res.emplace_back(args[i]...);
  return res;
}


vector<Int> identity(Int n){
  vector<Int> ord(n);
  iota(ord.begin(),ord.end(),0);
  return ord;
}

//INSERT ABOVE HERE
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);

  Int n,m;
  cin>>n>>m;
  auto A=make_v<Int>(n,m);
  for(Int i=0;i<n;i++)
    for(Int j=0;j<m;j++)
      cin>>A[i][j];

  vector<Int> sum(m);
  for(Int i=0;i<n;i++)
    for(Int j=0;j<m;j++)
      sum[j]+=A[i][j];

  vector<Int> sc(n,0);
  for(Int i=0;i<n;i++){
    for(Int j=0;j<m;j++)
      sc[i]+=A[i][j]*sum[j];
  }

  auto zs=zip(sc,identity(n));
  sort(zs.rbegin(),zs.rend());

  auto C=make_v<Int>(2,m);
  fill_v<Int>(C,0);

  Int pos=0;
  for(auto [_, i]:zs){
    for(Int j=0;j<m;j++)
      C[pos][j]+=A[i][j];
    pos^=1;
  }

  Int ans=0;
  for(Int j=0;j<m;j++)
    ans+=C[0][j]*C[0][j]-C[1][j]*C[1][j];
  cout<<ans<<endl;
  return 0;
}
0