QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#116304 | #5108. Prehistoric Programs | anhduc2701 | WA | 17ms | 10664kb | C++23 | 3.4kb | 2023-06-28 14:46:01 | 2023-06-28 14:46:03 |
Judging History
answer
/*
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
*/
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
#define len(x) ll(x.size())
#define eb emplace_back
#define PI acos(-1.0)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define MIN(v) *min_element(all(v))
#define MAX(v) *max_element(all(v))
#define BIT(x, i) (1 & ((x) >> (i)))
#define MASK(x) (1LL << (x))
#define task "tnc"
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
typedef long long ll;
typedef long double ld;
const ll INF = 1e18;
const int maxn = 1e6 + 5;
const int mod = 1e9 + 7;
const int mo = 998244353;
using pi = pair<ll, ll>;
using vi = vector<ll>;
using pii = pair<pair<ll, ll>, ll>;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
int n;
pair<pair<int, int>,int>k[maxn];
pair<int, int> st[maxn * 4];
void build(int id, int l, int r)
{
if (l == r)
{
st[id] = {k[l].fi.se, l};
return;
}
int mid = (l + r) / 2;
build(id * 2, l, mid);
build(id * 2 + 1, mid + 1, r);
st[id] = max(st[id * 2], st[id * 2 + 1]);
}
void update(int id, int l, int r, int u)
{
if (r < u || u < l)
return;
if (l == r)
{
st[id] = {-1e9, 0};
return;
}
int mid = (l + r) / 2;
update(id * 2, l, mid, u);
update(id * 2 + 1, mid + 1, r, u);
st[id] = max(st[id * 2], st[id * 2 + 1]);
}
pair<int, int> query(int id, int l, int r, int u, int v)
{
if (r < u || v < l)
{
return {-1e9, 0};
}
if (u <= l && r <= v)
{
return st[id];
}
int mid = (l + r) / 2;
return max(query(id * 2, l, mid, u, v), query(id * 2 + 1, mid + 1, r, u, v));
}
signed main()
{
cin.tie(0), cout.tie(0)->sync_with_stdio(0);
cin >> n;
int sum = 0;
for (int i = 1; i <= n; i++)
{
string s;
cin >> s;
int mi = 0;
int ans = 0;
for (auto &v : s)
{
if (v == '(')
{
ans++;
sum++;
}
else
{
ans--;
sum--;
}
mi = min(mi, ans);
}
k[i] = {{mi, ans},i};
}
if (sum != 0)
{
cout << "impossible";
return 0;
}
sort(k + 1, k + 1 + n, greater<pair<pair<int, int>,int>>());
build(1, 1, n);
int ht = 0;
vector<int>ans;
for (int i = 1; i <= n; i++)
{
int l = 1;
int r = n;
int d = 0;
while (l <= r)
{
int mid = (l + r) / 2;
if (abs(k[mid].fi.fi) <= ht)
{
l = mid + 1;
d = mid;
}
else
{
r = mid - 1;
}
}
if (d <= 0)
{
cout << "impossible";
return 0;
}
else
{
pair<int, int> cac = query(1, 1, n, 1, d);
ht += cac.fi;
ans.pb(k[cac.se].se);
update(1, 1, n, cac.se);
}
if (ht < 0)
{
cout << "impossible";
return 0;
}
}
for(auto v:ans){
cout<<v<<" ";
}
}
详细
Test #1:
score: 0
Wrong Answer
time: 17ms
memory: 10664kb
input:
50000 ( ( ))))()))()(()))()()()))()(((((()(((()))()(((()))((()(())))))(()( ) ( ) ((( ( ( ( ( ( () ( ) ( )((())()(( )))))( ( ) )) )() ( ) ) )()( ( ( () ( ) ( )()((((())()))())( ( ( )( ( ( (()())()) ) ) ( ( ( )((())))((())))))))))((((()()))()))))))))((()())())) ) )() ) ) ) ) ) ())(())))))()(()((()(())...
output:
impossible
result:
wrong answer you didn't find a solution but jury did