답안 #1099314

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1099314 2024-10-11T07:15:35 Z hegoplay Rabbit Carrot (LMIO19_triusis) C++17
14 / 100
2 ms 860 KB
/*
                                                                                                        -
                                                             +=
                                                           @@@@@%
                                                         +@@@@@@+
                                                      %@@@@@#%
                                                     @@@@@@@@=:
                       +******************         =@@@@@@@@@%
   =***********#*******+
                    %@@@@@@@@@@@@@@@@@@@@=         @@@@@@@@@@%
   #@@@@@@@@@@@@@@@@@@@@@@
                  +@@@@@@@@@@@@@@@@@@@@@+        +@@#@@@@@@@@%
   @@@@@@@@@@@@@@@@@@@@@@@=
                 +@@@@%                         *@@%@@@@@@@@@=    %@@@%
                 @@@@@#                        *@@@@@@@@@@@@#    #@@@@@
                %@@@@%                        +@@@@@@@@@@@@%
   @@@@@@@@@@@@@@@@@@@@%
               #@@@@@                        =#+@@@@@@@@#@%
   =@@@@@@@@@@@@@@@@@@@@*
              +@@@@@+                         #@@@@@@% =@@@@@=
             =@@@@@*                        #@@@@@@# @@@@@*
             #@@@@@@@@@@@@@@@@@@@@@       +@@@@@@# *@@@@@@@@@@@@@@@@@@@@@@#
             +@@@@@@@@@@@@@@@@@@@@=      %@@@@@% +@@@@@@@@@@@@@@@@@@@@@@+
               +*#************##*      =@@@@@#+ ###**##**#*******##*+
                                      =@@@@@@%
                                        +**  =+=
                                    Michael Jackson peeks
*/

#include <algorithm>
#include <bits/stdc++.h>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ext/pb_ds/assoc_container.hpp>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// Including tree_order_statistics_node_update
#include <ext/pb_ds/tree_policy.hpp>

#define pb push_back
#define inf 0x3f3f3f3f3f3f3f3f
#define all(x) (x).begin(), (x).end()
#define yes cout << "YES\n";
#define no cout << "NO\n";
#define sz(x) (int)(x).size()
#define el "\n"
typedef long long ll;
typedef long double ld;
#define int long long

using namespace std;
using namespace __gnu_pbds;

#define indexed_set                                                            \
  tree<int, null_type, less<int>, rb_tree_tag,                                 \
       tree_order_statistics_node_update>

void setIO(string name = "") {
  if (sz(name)) {
    freopen((name + ".in").c_str(), "r", stdin); // see /general/input-output
    freopen((name + ".out").c_str(), "w", stdout);
  }
}

void solve() {
  int n;
  cin >> n;
  int m;
  cin >> m;
  vector<int> vt(n + 1);
  for (int i = 1; i <= n; i++) {
    cin >> vt[i];
  }
  vt[0] = 0;
  set<int> s;
  map<int, pair<int, int>> mp;
  // tim
  // vi tri va so luong su thay doi can
  s.insert(0);
  mp[0] = {0, 0};
  for (int i = 1; i < vt.size(); i++) {
    int x = vt[i];
    int val = x - m * i;
    if(val > 0){
      continue;
    }
    int it = *s.lower_bound(val);
    
    pair<int,int> cur = mp[it];
    if ((s.find(val) != s.end()) && (mp[val].second + n - mp[val].first <  i - cur.first - 1 + cur.second)){
      continue;
    }
    else mp[val] = {i, i - cur.first - 1 + cur.second};
    
    s.insert(val);
    
  }

  ll res = LLONG_MAX;
  for (auto x : mp) {
    res = min(res, n - x.second.first + x.second.second);
  }
  cout << res;
}
signed main() {
  // #ifndef ONLINE_JUDGE
  //     freopen("input.txt", "r", stdin);
  //     freopen("out.txt", "w", stdout);
  // #endif
  //    setIO("cowjog");
  ios ::sync_with_stdio(false);
  cin.tie(nullptr);
  ll t = 1;
  // cin >> t;
  while (t--)
    solve();
  return 0;
}

Compilation message

triusis.cpp: In function 'void solve()':
triusis.cpp:91:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   91 |   for (int i = 1; i < vt.size(); i++) {
      |                   ~~^~~~~~~~~~~
triusis.cpp: In function 'void setIO(std::string)':
triusis.cpp:70:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   70 |     freopen((name + ".in").c_str(), "r", stdin); // see /general/input-output
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
triusis.cpp:71:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   71 |     freopen((name + ".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 452 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 452 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 456 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 860 KB Output is correct
21 Correct 2 ms 860 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 2 ms 860 KB Output is correct
24 Correct 1 ms 860 KB Output is correct
25 Incorrect 2 ms 860 KB Output isn't correct
26 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 860 KB Output is correct
5 Correct 2 ms 860 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 2 ms 860 KB Output is correct
8 Correct 1 ms 860 KB Output is correct
9 Incorrect 2 ms 860 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 860 KB Output is correct
5 Correct 2 ms 860 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 2 ms 860 KB Output is correct
8 Correct 1 ms 860 KB Output is correct
9 Incorrect 2 ms 860 KB Output isn't correct
10 Halted 0 ms 0 KB -