A번 문제 이해를 못해가지고 틀렸다. 칸에 있는 걸 움직여서 하나의 칸에 몰아주는 건 알겠는데 난 이동횟수만 계산해서 n^2-1인 줄 알았음. 알고보니 칸이 다른 칸으로 가는 최종 목적지와의 거리를 구해야 했다.
최소 횟수는 중간에 값을 모으면 구할 수 있다. 중간 상자를 기준으로 한 칸 떨어져 있는 상자의 이동횟수 두 칸 떨어져 있는 상자의 개수.. 이렇게 개수를 계산해서 이동 횟수를 더해주면 답이 나온다.
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <functional>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#define xx first
#define yy second
#define all(x) (x).begin(), (x).end()
#define MAX 1e9
using namespace std;
using i64 = long long;
using ii = pair<int, int>;
using ii64 = pair<i64, i64>;
void solve()
{
int n;
scanf("%d", &n);
i64 sum = 0;
i64 count = 1;
for (int i = 3; i <= n; i += 2)
{
sum += 4*(i-1)*count++;
}
printf("%lld\n", sum);
}
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++)
solve();
return 0;
}
'prompt' 카테고리의 다른 글
[토요라운드] 20/09/05 후기 (0) | 2020.09.05 |
---|---|
[Special Round 2] C. 작업 일지 (0) | 2020.07.18 |
[Special Round 2] A. 장난감 분류 (0) | 2020.07.18 |
[코드포스 Round 80] C. Little Dima and Equation (0) | 2020.07.06 |
[코드포스 Round 80] B. Buying Shovels (0) | 2020.07.06 |