結果

問題 No.1225 I hate I hate Matrix Construction
コンテスト
ユーザー firiexp
提出日時 2020-11-27 17:35:08
言語 C++17
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 907 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 607 ms
コンパイル使用メモリ 101,160 KB
最終ジャッジ日時 2026-06-15 09:35:11
合計ジャッジ時間 1,505 ms
ジャッジサーバーID
(参考情報)
judge1_1 / judge2_0
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:22:19: error: variable 'std::array<int, 3> cnt1' has initializer but incomplete type
   22 |     array<int, 3> cnt1{}, cnt2{};
      |                   ^~~~
main.cpp:10:1: note: 'std::array' is defined in header '<array>'; this is probably fixable by adding '#include <array>'
    9 | #include <cmath>
  +++ |+#include <array>
   10 | 
main.cpp:22:27: error: variable 'std::array<int, 3> cnt2' has initializer but incomplete type
   22 |     array<int, 3> cnt1{}, cnt2{};
      |                           ^~~~
main.cpp:22:27: note: 'std::array' is defined in header '<array>'; this is probably fixable by adding '#include <array>'

ソースコード

diff #
raw source code

#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n;
    cin >> n;
    array<int, 3> cnt1{}, cnt2{};
    for (int i = 0; i < n; ++i) {
        int x;
        scanf("%d", &x);
        cnt1[x]++;
    }
    for (int i = 0; i < n; ++i) {
        int x;
        scanf("%d", &x);
        cnt2[x]++;
    }
    int ans =  (cnt1[2]+cnt2[2])*n - cnt1[2]*cnt2[2];
    if(cnt1[2] && cnt2[2]) cout << ans << "\n";
    else if(cnt1[2]) cout << ans+cnt1[1] << "\n";
    else if(cnt2[2]) cout << ans+cnt2[1] << "\n";
    else cout << ans+max(cnt1[1], cnt2[1]) << "\n";
    return 0;
}
0