#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int>pi;
typedef pair<ll, ll>pl;
typedef vector<pi>vpi;
typedef vector<pl>vpl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<bool> vb;
const long double PI = acos(-1);
const ll oo = 1e18;
const int MOD = 1e9 + 7;
const int N = 2e5 + 7;
#define endl '\n'
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define read(v) for (auto& it : v) scanf("%d", &it);
#define readL(v) for (auto& it : v) scanf("%lld", &it);
#define print(v) for (auto it : v) printf("%d ", it); puts("");
#define printL(v) for (auto it : v) printf("%lld ", it); puts("");
void solve() {
int n;
cin >> n;
vi v(n);
for (auto& it : v)
cin >> it;
vb vis(n, false);
int ans = 0;
for (int i = 0; i < n; i++) {
if (vis[i])
continue;
int h = v[i];
ans++;
for (int j = 0; j < n; j++)
if (h == v[j] && !vis[j])
h--, vis[j] = true;
}
cout << ans << endl;
}
int t = 1;
int main() {
//#ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
//#endif
//scanf("%d", &t);
while (t--) solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
2 ms |
212 KB |
Output is correct |
3 |
Correct |
3 ms |
212 KB |
Output is correct |
4 |
Correct |
6 ms |
316 KB |
Output is correct |
5 |
Correct |
455 ms |
3396 KB |
Output is correct |
6 |
Correct |
1010 ms |
3864 KB |
Output is correct |
7 |
Correct |
862 ms |
3240 KB |
Output is correct |
8 |
Correct |
831 ms |
3208 KB |
Output is correct |
9 |
Correct |
636 ms |
3368 KB |
Output is correct |
10 |
Correct |
813 ms |
3488 KB |
Output is correct |