提出 #2946707


ソースコード 拡げる

#include <bits/stdc++.h>
using namespace std;
long long ans;
long long a;
vector<long long>vec;
long long n;
long long sum;
long long solve(vector<long long> tmp_vec) {
    for(int i = 0; i < n; i++) {
       sum += abs(tmp_vec.at(i) - tmp_vec.at(n/2)); 
    }
    return sum;
}
int main(int argc, char* argv[]) {
    scanf("%d", &n);
    for(int i = 0; i < n; i++) {
        scanf("%d", &a);
        vec.push_back(a - (i + 1));
    }
    sort(vec.begin(), vec.end());
    ans = solve(vec);
    cout << ans << endl;
    return 0;
}

提出情報

提出日時
問題 C - Linear Approximation
ユーザ moomin
言語 C++14 (GCC 5.4.1)
得点 300
コード長 554 Byte
結果 AC
実行時間 40 ms
メモリ 3440 KiB

コンパイルエラー

./Main.cpp: In function ‘int main(int, char**)’:
./Main.cpp:15:19: warning: format ‘%d’ expects argument of type ‘int*’, but argument 2 has type ‘long long int*’ [-Wformat=]
     scanf("%d", &n);
                   ^
./Main.cpp:17:23: warning: format ‘%d’ expects argument of type ‘int*’, but argument 2 has type ‘long long int*’ [-Wformat=]
         scanf("%d", &a);
                       ^
./Main.cpp:15:20: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
                    ^
./Main.cpp:17:24: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &a);
                        ^

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 300 / 300
結果
AC × 4
AC × 19
セット名 テストケース
Sample sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt
All sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt, sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt, subtask_1_01.txt, subtask_1_02.txt, subtask_1_03.txt, subtask_1_04.txt, subtask_1_05.txt, subtask_1_06.txt, subtask_1_07.txt, subtask_1_08.txt, subtask_1_09.txt, subtask_1_10.txt, subtask_1_11.txt
ケース名 結果 実行時間 メモリ
sample_01.txt AC 1 ms 256 KiB
sample_02.txt AC 1 ms 256 KiB
sample_03.txt AC 1 ms 256 KiB
sample_04.txt AC 1 ms 256 KiB
subtask_1_01.txt AC 1 ms 256 KiB
subtask_1_02.txt AC 8 ms 892 KiB
subtask_1_03.txt AC 6 ms 892 KiB
subtask_1_04.txt AC 15 ms 1908 KiB
subtask_1_05.txt AC 26 ms 3056 KiB
subtask_1_06.txt AC 29 ms 3440 KiB
subtask_1_07.txt AC 40 ms 3440 KiB
subtask_1_08.txt AC 30 ms 3440 KiB
subtask_1_09.txt AC 29 ms 3440 KiB
subtask_1_10.txt AC 29 ms 3440 KiB
subtask_1_11.txt AC 30 ms 3440 KiB