結果

問題 No.2178 Payable Magic Items
ユーザー mine691
提出日時 2022-09-27 04:17:03
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
RE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,224 bytes
コンパイル時間 2,177 ms
コンパイル使用メモリ 212,644 KB
最終ジャッジ日時 2025-02-07 16:58:30
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1 RE * 3
other AC * 1 RE * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

// 愚直高速化 set<int> ver.

#include <bits/stdc++.h>
using namespace std;
using Int = long long;
constexpr static int mod = 1e9 + 7;
constexpr static int inf = (1 << 30) - 1;
constexpr static Int infll = (1LL << 61) - 1;
int Competitive_Programming = (ios_base::sync_with_stdio(false), cin.tie(nullptr), cout << fixed << setprecision(15), 0);

int main()
{
	int N, K;
	cin >> N >> K;
	vector<string> s(N);
	vector<int> d(N);

	for (int i = 0; i < N; i++)
		cin >> s[i];

	vector<set<int>> st(32);

	sort(s.begin(), s.end(), [](string &a, string &b)
		 { 
		int ret1 = 0, ret2 = 0;
		for (int j = 0; j < a.size(); j++)
			ret1 += abs(a[j] - 'D'), ret2 += abs(b[j] - 'D');
			return ret1 > ret2; });

	for (int i = 0; i < N; i++)
	{
		for (int j = 0; j < K; j++)
			d[i] += abs(s[i][j] - 'D');
		st[d[i]].insert(i);
	}

	int ans = 0;

	for (int i = 0; i < N; i++)
	{
		for (int j = 0; j < d[i]; j++)
		{
			vector<int> del;
			for (auto &&l : st[j])
			{
				if (i == l)
					continue;
				int cnt = 0;
				for (int k = 0; k < K; k++)
					cnt += (s[i][k] <= s[l][k]);

				if (cnt == K)
				{
					del.emplace_back(l);
					ans++;
				}
			}
			for (auto &&l : del)
				st[j].erase(l);
		}
	}

	cout << ans << "\n";
}
0