Submission #44052028


Source Code Expand

// time-limit: 2000
// problem-url: https://atcoder.jp/contests/abc312/tasks/abc312_d
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <array>
#include <random>
#include <cmath>
#include <chrono>
#include <list>
#include <ctime>
#include <sstream>
#include <queue>
#include <climits>
#include <stack>
#include <valarray>
#include <random>
#include <bitset>
#include <numeric>
#include <iomanip>
#include <cassert>
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;
#define rep(x, b, e) for(int x=(b); x<(e); ++x)
#define trav(a, x) for(auto& a : x)
#define ford(x, b, e) for(int x=((int)(b))-1; x>=(e); --x)
#define all(c) c.begin(),c.end()
#define sz(x) ((int)((x).size()))
#define pb push_back
#define eb emplace_back
#define st first
#define nd second
#define mp(x,y) make_pair(x,y)
typedef short int sint;
template<typename T> bool ckmin(T& a, const T& b){return b<a?a=b,1:0;}
template<typename T> bool ckmax(T& a, const T& b){return b>a?a=b,1:0;}


template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) {
  return '"' + s + '"';
}

string to_string(char c) {
  return string(1, c);
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}

template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif


#include <atcoder/modint>
using namespace atcoder;
using mint = modint998244353; // modint1000000007;
typedef vector<mint> vmi;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); // use rng() to get unsigned int
// mt19937_64 for random long longs

void solve() {
	string s;
  cin >> s;
  s = '0' + s;
  int n = sz(s);
  vmi dp(n + 1);
  dp[0] = 1;
  debug(s);
  rep(i, 1, n) {
    debug("znak" , i, s[i]);
    vmi ndp(n + 1);
    if (s[i] == '(' || s[i] == '?') {
      rep(j, 1, i + 1) {
        ndp[j] += dp[j - 1];
      }
    }
    if (s[i] == ')' || s[i] == '?') {
      rep(j, 0, i) {
        ndp[j] += dp[j + 1];
      }
    }
    dp = ndp;
    rep(i, 0, n) {
      debug(i, dp[i].val());
    }
  }
  cout << (dp[0].val()) << endl;
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	int t;
	// cin >> t;
	t = 1;
	while (t--) {
		solve();
	}
}

Submission Info

Submission Time
Task D - Count Bracket Sequences
User zglicz
Language C++ (GCC 9.2.1)
Score 400
Code Size 4167 Byte
Status AC
Exec Time 18 ms
Memory 3620 KiB

Compile Error

./Main.cpp: In function ‘void solve()’:
./Main.cpp:134:20: warning: statement has no effect [-Wunused-value]
  134 | #define debug(...) 42
      |                    ^~
./Main.cpp:153:3: note: in expansion of macro ‘debug’
  153 |   debug(s);
      |   ^~~~~
./Main.cpp:134:20: warning: statement has no effect [-Wunused-value]
  134 | #define debug(...) 42
      |                    ^~
./Main.cpp:155:5: note: in expansion of macro ‘debug’
  155 |     debug("znak" , i, s[i]);
      |     ^~~~~
./Main.cpp:134:20: warning: statement has no effect [-Wunused-value]
  134 | #define debug(...) 42
      |                    ^~
./Main.cpp:169:7: note: in expansion of macro ‘debug’
  169 |       debug(i, dp[i].val());
      |       ^~~~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 3
AC × 24
Set Name Test Cases
Sample sample00.txt, sample01.txt, sample02.txt
All sample00.txt, sample01.txt, sample02.txt, testcase00.txt, testcase01.txt, testcase02.txt, testcase03.txt, testcase04.txt, testcase05.txt, testcase06.txt, testcase07.txt, testcase08.txt, testcase09.txt, testcase10.txt, testcase11.txt, testcase12.txt, testcase13.txt, testcase14.txt, testcase15.txt, testcase16.txt, testcase17.txt, testcase18.txt, testcase19.txt, testcase20.txt
Case Name Status Exec Time Memory
sample00.txt AC 7 ms 3504 KiB
sample01.txt AC 2 ms 3500 KiB
sample02.txt AC 2 ms 3428 KiB
testcase00.txt AC 2 ms 3408 KiB
testcase01.txt AC 2 ms 3412 KiB
testcase02.txt AC 2 ms 3368 KiB
testcase03.txt AC 9 ms 3440 KiB
testcase04.txt AC 10 ms 3600 KiB
testcase05.txt AC 16 ms 3524 KiB
testcase06.txt AC 13 ms 3452 KiB
testcase07.txt AC 17 ms 3544 KiB
testcase08.txt AC 8 ms 3392 KiB
testcase09.txt AC 18 ms 3460 KiB
testcase10.txt AC 14 ms 3464 KiB
testcase11.txt AC 15 ms 3620 KiB
testcase12.txt AC 6 ms 3568 KiB
testcase13.txt AC 15 ms 3604 KiB
testcase14.txt AC 10 ms 3440 KiB
testcase15.txt AC 17 ms 3404 KiB
testcase16.txt AC 14 ms 3464 KiB
testcase17.txt AC 15 ms 3452 KiB
testcase18.txt AC 9 ms 3592 KiB
testcase19.txt AC 11 ms 3448 KiB
testcase20.txt AC 15 ms 3540 KiB