結果

問題 No.2673 A present from B
ユーザー ゆにぽけゆにぽけ
提出日時 2024-03-15 22:01:12
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,172 bytes
コンパイル時間 1,322 ms
コンパイル使用メモリ 133,556 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-03-15 22:01:15
合計ジャッジ時間 2,757 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 WA -
testcase_05 AC 2 ms
6,676 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 2 ms
6,676 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 2 ms
6,676 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 2 ms
6,676 KB
testcase_23 AC 2 ms
6,676 KB
testcase_24 AC 2 ms
6,676 KB
testcase_25 AC 2 ms
6,676 KB
testcase_26 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <array>
#include <iterator>
#include <string>
#include <cctype>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <cmath>
#include <ctime>
#include <iomanip>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <bitset>
#include <random>
#include <utility>
#include <functional>
using namespace std;
void Main()
{
	int N,M;
	cin >> N >> M;
	vector<vector<int>> P(M + 1);
	P[0].resize(N);
	iota(P[0].begin(),P[0].end(),0);
	for(int i = 1;i <= M;i++)
	{
		P[i] = P[i - 1];
		int a;
		cin >> a;
		a--;
		swap(P[i][a],P[i][a + 1]);
	}
	vector<int> ans(N,(int)1e9);
	int f = P[M][0];
	for(int i = 1;i < N;i++)
	{
		for(int j = 0;j <= M;j++)
		{
			int l = -1,r = -1;
			for(int k = 0;k < N;k++)
			{
				if(P[j][k] == i)
				{
					l = k;
				}
				if(P[j][k] == f)
				{
					r = k;
				}
			}
			ans[i] = min(ans[i],abs(l - r));
		}
		cout << ans[i] << (i + 1 == N ? "\n" : " ");
	}
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int tt = 1;
	/* cin >> tt; */
	while(tt--) Main();
}

0