Submission #32155305


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a,n) for (ll i=a;i<(ll)n;i++)
ll read(){ll r;scanf("%lld",&r);return r;} // read
int p[400010];
int q[400010];
char s[400010];
char sets(int i,char ch){
  return (s[i] && s[i] != ch) ? 0 : (s[i] = ch);
}
bool work(){
  int n = read() * 2; // 2e5 * 2
  rep(i,0,n) p[i] = read() - 1;
  rep(i,0,n) q[i] = read() - 1;
  for(auto [arr, cmp]:vector<pair<int *,int> > {{p, 1},{q,-1}}){
    rep(i,0,n-1) {
      if((arr[i] - arr[i+1]) * cmp <= 0) continue; // 出现反序列
      if(!sets(arr[i],'(') || !sets(arr[i+1],')')) return false;
    }
  }
  rep(i,0,n) if(!s[i]) return false; // 不唯一
  // check 可能一个合法 另一个不合法
  for(auto [arr,st,d]:vector<tuple<int*,int,int> >{{p,0,1},{q,n-1,-1}}){
    // 双指针
    int i0 = st; // 找所有值
    int i1 = st; // 只找左括号
    int cnt = 0;
    vector<bool> vis(n,false);
    rep(i,0,n){
      int pos ; // 选取的位置
      if(cnt == 0){
        while(vis[i1] || s[i1] != '(') i1+=d;
        pos = i1;
      }else{ // cnt > 0
        while(vis[i0])i0+=d;
        pos = i0;
      }
      if(arr[i] != pos) return false; // 和提供的不一致
      vis[pos] = true;
      cnt += s[pos] == '('?1:-1;
    }
    if(cnt) return false;
  }
  printf("%s\n",s);
  return true;
}
int main(){
  if(!work()) printf("-1\n");
  return 0;
}

Submission Info

Submission Time
Task C - Bracket and Permutation
User cromarmot
Language C++ (GCC 9.2.1)
Score 600
Code Size 1393 Byte
Status AC
Exec Time 85 ms
Memory 7228 KiB

Compile Error

./Main.cpp: In function ‘ll read()’:
./Main.cpp:5:21: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
    5 | ll read(){ll r;scanf("%lld",&r);return r;} // read
      |                ~~~~~^~~~~~~~~~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 600 / 600
Status
AC × 3
AC × 57
Set Name Test Cases
Sample 00-sample-001.txt, 00-sample-002.txt, 00-sample-003.txt
All 00-sample-001.txt, 00-sample-002.txt, 00-sample-003.txt, 02-random-001.txt, 02-random-002.txt, 02-random-003.txt, 02-random-004.txt, 02-random-005.txt, 02-random-006.txt, 02-random-007.txt, 02-random-008.txt, 02-random-009.txt, 02-random-010.txt, 02-random-011.txt, 02-random-012.txt, 02-random-013.txt, 02-random-014.txt, 02-random-015.txt, 02-random-016.txt, 02-random-017.txt, 02-random-018.txt, 02-random-019.txt, 02-random-020.txt, 02-random-021.txt, 02-random-022.txt, 02-random-023.txt, 02-random-024.txt, 02-random-025.txt, 03-no-001.txt, 03-no-002.txt, 03-no-003.txt, 03-no-004.txt, 03-no-005.txt, 03-no-006.txt, 03-no-007.txt, 03-no-008.txt, 03-no-009.txt, 03-no-010.txt, 03-no-011.txt, 03-no-012.txt, 03-no-013.txt, 03-no-014.txt, 03-no-015.txt, 03-no-016.txt, 03-no-017.txt, 03-no-018.txt, 03-no-019.txt, 03-no-020.txt, 03-no-021.txt, 03-no-022.txt, 03-no-023.txt, 03-no-024.txt, 03-no-025.txt, 04-hand-001.txt, 04-hand-002.txt, 04-hand-003.txt, 04-hand-004.txt
Case Name Status Exec Time Memory
00-sample-001.txt AC 7 ms 3636 KiB
00-sample-002.txt AC 2 ms 3460 KiB
00-sample-003.txt AC 2 ms 3548 KiB
02-random-001.txt AC 81 ms 7188 KiB
02-random-002.txt AC 77 ms 7104 KiB
02-random-003.txt AC 81 ms 7148 KiB
02-random-004.txt AC 75 ms 7136 KiB
02-random-005.txt AC 79 ms 7100 KiB
02-random-006.txt AC 79 ms 7204 KiB
02-random-007.txt AC 83 ms 7012 KiB
02-random-008.txt AC 80 ms 7092 KiB
02-random-009.txt AC 84 ms 7144 KiB
02-random-010.txt AC 76 ms 7136 KiB
02-random-011.txt AC 75 ms 6964 KiB
02-random-012.txt AC 81 ms 7152 KiB
02-random-013.txt AC 74 ms 6860 KiB
02-random-014.txt AC 80 ms 7192 KiB
02-random-015.txt AC 82 ms 7188 KiB
02-random-016.txt AC 84 ms 7060 KiB
02-random-017.txt AC 81 ms 7228 KiB
02-random-018.txt AC 83 ms 7144 KiB
02-random-019.txt AC 81 ms 7060 KiB
02-random-020.txt AC 81 ms 7144 KiB
02-random-021.txt AC 81 ms 7044 KiB
02-random-022.txt AC 84 ms 7192 KiB
02-random-023.txt AC 85 ms 7144 KiB
02-random-024.txt AC 83 ms 7152 KiB
02-random-025.txt AC 81 ms 7008 KiB
03-no-001.txt AC 76 ms 7104 KiB
03-no-002.txt AC 75 ms 6952 KiB
03-no-003.txt AC 74 ms 6812 KiB
03-no-004.txt AC 74 ms 6852 KiB
03-no-005.txt AC 75 ms 6780 KiB
03-no-006.txt AC 76 ms 6776 KiB
03-no-007.txt AC 77 ms 6892 KiB
03-no-008.txt AC 74 ms 6664 KiB
03-no-009.txt AC 74 ms 6764 KiB
03-no-010.txt AC 77 ms 6916 KiB
03-no-011.txt AC 81 ms 7008 KiB
03-no-012.txt AC 79 ms 7188 KiB
03-no-013.txt AC 77 ms 7188 KiB
03-no-014.txt AC 80 ms 7188 KiB
03-no-015.txt AC 77 ms 7192 KiB
03-no-016.txt AC 79 ms 7188 KiB
03-no-017.txt AC 77 ms 7148 KiB
03-no-018.txt AC 79 ms 7188 KiB
03-no-019.txt AC 77 ms 7200 KiB
03-no-020.txt AC 78 ms 7144 KiB
03-no-021.txt AC 76 ms 7144 KiB
03-no-022.txt AC 75 ms 6804 KiB
03-no-023.txt AC 75 ms 6908 KiB
03-no-024.txt AC 78 ms 6784 KiB
03-no-025.txt AC 75 ms 6928 KiB
04-hand-001.txt AC 2 ms 3640 KiB
04-hand-002.txt AC 83 ms 7192 KiB
04-hand-003.txt AC 80 ms 7192 KiB
04-hand-004.txt AC 77 ms 7200 KiB