답안 #633546

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
633546 2022-08-22T17:35:36 Z BidoTeima Baloni (COCI15_baloni) C++17
0 / 100
24 ms 47372 KB
/// isA AC
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void ACPLS()
{
#ifndef ONLINE_JUDGE
    freopen("output.txt", "w", stdout);
    freopen("input.txt", "r", stdin);
#endif
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
void moo(string fileName){
    freopen((fileName+".in").c_str(),"r",stdin);
    freopen((fileName+".out").c_str(),"w",stdout);
}
#define tc         \
    int tttttt,subtask;    \
    cin >> tttttt /*>> subtask*/; \
    while (tttttt--)
#define sumrange(l, r, arr) (l == 0 ? arr[r] : arr[r] - arr[l - 1])
#define all(v) v.begin(), v.end()
set<int>occ[(int)1e6+5];
int freq[(int)1e6+5];
int cur[(int)1e6+5];
int main()
{
	ACPLS();
	int n;
    cin>>n;
    int a[n];
    for(int&i:a)cin>>i;
    reverse(a,a+n);
    for(int i = 0; i < n; i++){
        occ[a[i]].insert(i);
        freq[a[i]]++;
    }
    int ans = 0;
    for(int i = 0; i < n; i++){
        if(occ[a[i] + 1].empty()){
            ans += freq[a[i]] - cur[a[i]];
            ++cur[a[i]];
            continue;
        }
        auto it = prev(occ[a[i] + 1].end());
        if(*it < i)
            ans += freq[a[i]] - cur[a[i]];
        occ[a[i] + 1].erase(prev(occ[a[i] + 1].end()));
        ++cur[a[i]];
    }
    cout<<ans;
}	

Compilation message

baloni.cpp: In function 'void ACPLS()':
baloni.cpp:8:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    8 |     freopen("output.txt", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
baloni.cpp:9:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 |     freopen("input.txt", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
baloni.cpp: In function 'void moo(std::string)':
baloni.cpp:16:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |     freopen((fileName+".in").c_str(),"r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
baloni.cpp:17:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |     freopen((fileName+".out").c_str(),"w",stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 23 ms 47316 KB Output isn't correct
2 Incorrect 23 ms 47360 KB Output isn't correct
3 Incorrect 22 ms 47340 KB Output isn't correct
4 Incorrect 23 ms 47364 KB Output isn't correct
5 Incorrect 23 ms 47368 KB Output isn't correct
6 Incorrect 24 ms 47372 KB Output isn't correct
7 Incorrect 23 ms 47296 KB Output isn't correct
8 Incorrect 23 ms 47316 KB Output isn't correct
9 Incorrect 24 ms 47368 KB Output isn't correct
10 Incorrect 23 ms 47248 KB Output isn't correct