結果

問題 No.831 都市めぐり
ユーザー kotamanegikotamanegi
提出日時 2019-05-24 22:43:24
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 2,741 bytes
コンパイル時間 912 ms
コンパイル使用メモリ 107,700 KB
実行使用メモリ 26,836 KB
最終ジャッジ日時 2023-10-17 13:00:55
合計ジャッジ時間 2,001 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 RE -
testcase_02 AC 1 ms
4,348 KB
testcase_03 WA -
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 4 ms
4,412 KB
testcase_13 AC 3 ms
4,412 KB
testcase_14 AC 4 ms
4,412 KB
testcase_15 AC 16 ms
13,152 KB
testcase_16 AC 9 ms
7,420 KB
testcase_17 AC 18 ms
15,000 KB
testcase_18 AC 25 ms
22,360 KB
testcase_19 AC 30 ms
25,780 KB
testcase_20 AC 31 ms
26,836 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream> 
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>  
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000000000000000000000001
#define LONG_INF 10000000000000000LL
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD  998244353
#define REP(i,n) for(long long i = 0;i < n;++i)
long long inv(long long now) {
	long long ans = 1;
	long long te = MAX_MOD - 2LL;
	while (te != 0) {
		if (te % 2 == 1) {
			ans *= now;
			ans %= MAX_MOD;
		}
		te /= 2;
		now *= now;
		now %= MAX_MOD;
	}
	return ans;
}
int used[4000000] = {};
long long solve(long long n) {
	long long now_ans = 0;
	vector<long long> gogo[2];
	gogo[0].push_back(1);
	gogo[1].push_back(1);
	long long now_bot = 2;
	long long now_top = n;
	used[1] = 2;
	for (int i = 0;; ++i) {
		if (i % 2 == 0) {
			gogo[0].push_back(now_top);
			used[now_top]++;
			if (used[now_top] == 2) break;
			now_top--;
			gogo[1].push_back(now_top);
			used[now_top]++;
			if (used[now_top] == 2) break;
			now_top--;
		}
		else {
			gogo[0].push_back(now_bot);
			used[now_bot]++;
			if (used[now_bot] == 2) break;
			now_bot++;
			gogo[1].push_back(now_bot);
			used[now_bot]++;
			if (used[now_bot] == 2) break;
			now_bot++;
		}
	}
	if (n % 2 == 0) {
		gogo[1].pop_back();
		now_ans += gogo[1][gogo[1].size() - 1] * gogo[0][gogo[0].size() - 1];
	}
	for (int i = 0; i < gogo[0].size() - 1; ++i) {
		now_ans += gogo[0][i] * gogo[0][i + 1];
	}
	REP(i, gogo[1].size() - 1) {
		now_ans += gogo[1][i] * gogo[1][i + 1];
	}
	return now_ans;
}
int main(){
	long long n;
	cin >> n;
	cout << solve(n) << endl;
	return 0;
	vector<long long> gogo;
	for (int i = 1; i <= n; ++i) {
		gogo.push_back(i);
	}
	long long ans = LONG_INF;
	vector<vector<long long>> now_te;
	do {
		if (gogo[0] != 1) break;
		long long now_ans = 0;
		for (int i = 0; i < gogo.size() - 1; ++i) {
			now_ans += gogo[i] * gogo[i + 1];
		}
		now_ans += gogo[0] * gogo[gogo.size() - 1];
		if (now_ans == ans) {
			now_te.push_back(gogo);
		}
		else if (now_ans < ans) {
			ans = now_ans;
			now_te.clear();
			now_te.push_back(gogo);
		}
	} while (next_permutation(gogo.begin(), gogo.end()));
	cout << ans << endl;
	REP(i, now_te.size()) {
		REP(q, now_te[i].size()) {
			cout << now_te[i][q] << " ";
		}
		cout << endl;
	}
	return 0;
}
0