提出 #64755013


ソースコード 拡げる

#ifndef IO_HPP
#define IO_HPP 1

#include <array>
#include <cstdint>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

namespace io {

void __read(char& c) { std::cin >> c; }
void __read(std::string& s) { std::cin >> s; }

template <typename T>
void __read_real(T& x) {
  std::string s;
  __read(s);
  x = std::stod(s);
}

template <typename T>
void __read_integer(T& x) {
  std::cin >> x;
}

void __read(int& x) { __read_integer(x); }
void __read(unsigned int& x) { __read_integer(x); }
void __read(long& x) { __read_integer(x); }
void __read(unsigned long& x) { __read_integer(x); }
void __read(long long& x) { __read_integer(x); }
void __read(unsigned long long& x) { __read_integer(x); }
void __read(double& x) { __read_real(x); }
void __read(long double& x) { __read_real(x); }

template <class U, class V>
void __read(std::pair<U, V>& p) {
  __read(p.first);
  __read(p.second);
}

template <size_t N = 0, typename T>
void __read_tuple(T& t) {
  if constexpr (N < std::tuple_size<T>::value) {
    auto& x = std::get<N>(t);
    __read(x);
    __read_tuple<N + 1>(t);
  }
}
template <class... T>
void __read(std::tuple<T...>& t) {
  __read_tuple(t);
}

template <size_t N = 0, typename T>
void __read(std::array<T, N>& a) {
  for (auto& x : a) {
    __read(x);
  }
}

template <class T>
void __read(std::vector<T>& v) {
  for (auto& x : v) {
    __read(x);
  }
}

void read() {}
template <class H, class... T>
void read(H& h, T&... t) {
  __read(h), read(t...);
}

void __write(const char c) { std::cout << c; }

void __write(const std::string s) {
  for (char c : s) {
    __write(c);
  }
}

void __write(const char* s) {
  size_t len = strlen(s);
  for (size_t i = 0; i < len; ++i) {
    __write(s[i]);
  }
}

template <typename T>
void __write_integer(T x) {
  std::cout << x;
}

template <typename T>
void __write_real(T x) {
  std::ostringstream oss;
  oss << std::fixed << std::setprecision(15) << double(x);
  std::string s = oss.str();
  __write(s);
}

void __write(int x) { __write_integer(x); }
void __write(unsigned int x) { __write_integer(x); }
void __write(long x) { __write_integer(x); }
void __write(unsigned long x) { __write_integer(x); }
void __write(long long x) { __write_integer(x); }
void __write(unsigned long long x) { __write_integer(x); }
void __write(double x) { __write_real(x); }
void __write(long double x) { __write_real(x); }

template <class U, class V>
void __write(const std::pair<U, V> p) {
  __write(p.first);
  __write(' ');
  __write(p.second);
}

template <size_t N = 0, typename T>
void __write_tuple(const T t) {
  if constexpr (N < std::tuple_size<T>::value) {
    if constexpr (N > 0) {
      __write(' ');
    }
    const auto x = std::get<N>(t);
    __write(x);
    __write_tuple<N + 1>(t);
  }
}
template <class... T>
void __write(std::tuple<T...> t) {
  __write_tuple(t);
}

template <class T, size_t S>
void __write(const std::array<T, S> a) {
  auto n = a.size();
  for (size_t i = 0; i < n; i++) {
    if (i) {
      __write(' ');
    }
    __write(a[i]);
  }
}

template <class T>
void __write(const std::vector<T> v) {
  auto n = v.size();
  for (size_t i = 0; i < n; i++) {
    if (i) {
      __write(' ');
    }
    __write(v[i]);
  }
}

template <class T>
void __write(const std::set<T> s) {
  __write(std::vector<T>{s.cbegin(), s.cend()});
}

template <class K, class V>
void __write(const std::map<K, V> m) {
  __write(std::vector<std::pair<K, V>>{m.cbegin(), m.cend()});
}

void write() { __write('\n'); }
template <class Head, class... Tail>
void write(Head&& head, Tail&&... tail) {
  __write(head);
  if (sizeof...(Tail)) {
    __write(' ');
  }
  write(std::forward<Tail>(tail)...);
}

}  // namespace io

#endif  // IO_HPP

#ifdef ONLINE_JUDGE
#include <bits/allocator.h>
#pragma GCC optimize("Ofast,unroll-loops,inline")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#endif

#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
// using namespace atcoder;
using namespace io;

template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

string solve() {
  int n, k;
  string s;
  read(n, k, s);
  for (int i{1}; i < n; ++i) {
    if (s[i - 1] == 'o') {
      s[i] = '.';
    }
  }
  for (int i{n - 1}; i > 0; --i) {
    if (s[i] == 'o') {
      s[i - 1] = '.';
    }
  }
  s = "." + s + ".";
  n = s.length();
  k -= count(s.cbegin(), s.cend(), 'o');
  if (!k) {
    for (auto& c : s) {
      if (c == '?') {
        c = '.';
      }
    }
    return s.substr(1, n - 2);
  }
  int m{};
  vector<pair<int, int>> gaps;
  for (int prev{0}, curr{}; curr < n; ++curr) {
    if (s[curr] == '.') {
      if (curr - prev > 1) {
        gaps.emplace_back(prev, curr);
        m += (curr - prev) / 2;
      }
      prev = curr;
    } else if (s[curr] == 'o') {
      prev = curr;
    }
  }
  if (m > k) {
    return s.substr(1, n - 2);
  }
  for (auto& [l, r] : gaps) {
    if ((r & 1) == (l & 1)) {
      for (int i{l + 1}; i < r; ++i) {
        if ((i & 1) == (l & 1)) {
          s[i] = '.';
        } else {
          s[i] = 'o';
        }
      }
    }
  }
  return s.substr(1, n - 2);
}

int main() {
  cin.tie(0)->sync_with_stdio(0);
  write(solve());
}

提出情報

提出日時
問題 D - Logical Filling
ユーザ nika_skybytska
言語 C++ 20 (gcc 12.2)
得点 400
コード長 5685 Byte
結果 AC
実行時間 5 ms
メモリ 4028 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 400 / 400
結果
AC × 3
AC × 43
セット名 テストケース
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 01_random_27.txt, 01_random_28.txt, 01_random_29.txt, 01_random_30.txt, 01_random_31.txt, 01_random_32.txt, 01_random_33.txt, 01_random_34.txt, 01_random_35.txt, 01_random_36.txt, 01_random_37.txt, 01_random_38.txt, 01_random_39.txt
ケース名 結果 実行時間 メモリ
00_sample_00.txt AC 1 ms 3412 KiB
00_sample_01.txt AC 1 ms 3392 KiB
00_sample_02.txt AC 1 ms 3480 KiB
01_random_00.txt AC 2 ms 3696 KiB
01_random_01.txt AC 5 ms 3836 KiB
01_random_02.txt AC 5 ms 3796 KiB
01_random_03.txt AC 1 ms 3592 KiB
01_random_04.txt AC 2 ms 3580 KiB
01_random_05.txt AC 3 ms 3616 KiB
01_random_06.txt AC 4 ms 3740 KiB
01_random_07.txt AC 4 ms 3840 KiB
01_random_08.txt AC 1 ms 3548 KiB
01_random_09.txt AC 4 ms 3892 KiB
01_random_10.txt AC 4 ms 3884 KiB
01_random_11.txt AC 4 ms 3988 KiB
01_random_12.txt AC 4 ms 3868 KiB
01_random_13.txt AC 4 ms 4012 KiB
01_random_14.txt AC 4 ms 3880 KiB
01_random_15.txt AC 4 ms 3932 KiB
01_random_16.txt AC 4 ms 3948 KiB
01_random_17.txt AC 4 ms 3856 KiB
01_random_18.txt AC 4 ms 3936 KiB
01_random_19.txt AC 4 ms 3936 KiB
01_random_20.txt AC 3 ms 3896 KiB
01_random_21.txt AC 3 ms 3840 KiB
01_random_22.txt AC 3 ms 3888 KiB
01_random_23.txt AC 1 ms 3624 KiB
01_random_24.txt AC 1 ms 3348 KiB
01_random_25.txt AC 1 ms 3620 KiB
01_random_26.txt AC 1 ms 3484 KiB
01_random_27.txt AC 3 ms 4028 KiB
01_random_28.txt AC 3 ms 3820 KiB
01_random_29.txt AC 3 ms 3900 KiB
01_random_30.txt AC 3 ms 3904 KiB
01_random_31.txt AC 3 ms 3820 KiB
01_random_32.txt AC 3 ms 3900 KiB
01_random_33.txt AC 3 ms 3892 KiB
01_random_34.txt AC 3 ms 3968 KiB
01_random_35.txt AC 3 ms 3884 KiB
01_random_36.txt AC 3 ms 4020 KiB
01_random_37.txt AC 3 ms 4024 KiB
01_random_38.txt AC 3 ms 3816 KiB
01_random_39.txt AC 3 ms 3840 KiB