QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#425316 | #6537. One, Two, Three | crsfaa | WA | 1ms | 4176kb | C++14 | 2.4kb | 2024-05-30 08:26:56 | 2024-05-30 08:26:57 |
Judging History
answer
#include<bits/stdc++.h>
#define Yukinoshita namespace
#define Yukino std
using Yukinoshita Yukino;
int read()
{
int s=0;
char ch=getchar();
while(ch<'0'||ch>'9') ch=getchar();
while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
return s;
}
using vec=vector<int>;
stack<vec> A,C,AB,CB;
stack<vec> ABC,ACB,ABCB;
//CBAB A
//CBA AB
vec get(stack<vec> &a)
{
vec res=a.top();
a.pop();
return res;
}
vec operator +(vec x,vec y)
{
for(auto i:y) x.push_back(i);
return x;
}
const int mxn=6e6+5;
char s[mxn];
/*
CABBCA
6
3 1 2 2 3 1
6
1 2 3 2 1 3
*/
int main()
{
int n=read(),i;
for(i=0;i<n;i++)
{
int x=read()+'A'-1;
s[i]=x;
if(x=='A')
{
if(CB.size())
ABC.push(get(CB)+vec{i});
else if(ABCB.size())
{
vec tp=get(ABCB);
if(s[tp[0]]==x)
AB.push({tp[0],tp[1]}),
ABC.push({tp[2],tp[3],i});
else
AB.push({tp[2],tp[3]}),
ABC.push({tp[0],tp[1],i});
}
else if(ACB.size())
{
vec tp=get(ACB);
if(s[tp[0]]==x)
ABC.push({tp[1],tp[2],i}),
A.push({tp[0]});
else
ABC.push({tp[0],tp[2],i}),
A.push({tp[1]});
}
else A.push({i});
}
if(x=='B')
{
if(ACB.size())
{
vec tp=get(ACB);
if(s[tp[0]]=='A')
AB.push({tp[0],i}),
CB.push({tp[1],tp[2]});
else
CB.push({tp[0],i}),
AB.push({tp[1],tp[2]});
}
else if(A.size()&&C.size())
{
vec ta=get(A),tb=get(C);
ACB.push({min(ta[0],tb[0]),max(ta[0],tb[0]),i});
}
else if(ABC.size())
ABCB.push(get(ABC)+vec{i});
else if(A.size())
AB.push(get(A)+vec{i});
else if(C.size())
CB.push(get(C)+vec{i});
}
if(x=='C')
{
if(AB.size())
ABC.push(get(AB)+vec{i});
else if(ABCB.size())
{
vec tp=get(ABCB);
if(s[tp[0]]==x)
CB.push({tp[0],tp[1]}),
ABC.push({tp[2],tp[3],i});
else
CB.push({tp[2],tp[3]}),
ABC.push({tp[0],tp[1],i});
}
else if(ACB.size())
{
vec tp=get(ACB);
if(s[tp[0]]==x)
ABC.push({tp[1],tp[2],i}),
C.push({tp[0]});
else
ABC.push({tp[0],tp[2],i}),
C.push({tp[1]});
}
else C.push({i});
}
}
printf("%d\n",ABC.size()+ABCB.size());
for(;ABC.size();ABC.pop())
printf("%d %d %d\n",ABC.top()[0],ABC.top()[1],ABC.top()[2]);
for(;ABCB.size();ABCB.pop())
printf("%d %d %d\n",ABCB.top()[0],ABCB.top()[1],ABCB.top()[2]);
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3812kb
input:
6 3 1 2 2 3 1
output:
2 0 3 5 1 2 4
result:
ok count=2
Test #2:
score: 0
Accepted
time: 0ms
memory: 3844kb
input:
6 2 1 3 1 3 2
output:
0
result:
ok count=0
Test #3:
score: 0
Accepted
time: 1ms
memory: 3924kb
input:
3000 1 1 1 1 1 3 1 1 3 3 1 3 1 1 2 3 1 1 2 1 2 1 3 3 3 1 1 2 1 2 2 3 1 1 1 1 1 1 1 2 1 1 1 1 1 1 2 3 3 1 1 2 1 1 2 1 1 1 1 1 2 1 1 1 1 1 1 2 1 1 1 2 3 1 1 1 1 3 3 2 1 3 1 1 2 3 1 2 3 1 1 1 2 1 1 1 1 2 3 2 1 1 1 1 1 2 1 1 1 1 1 1 1 2 1 1 1 3 1 3 3 1 1 1 1 3 1 1 2 1 1 1 3 3 1 1 1 1 2 1 1 1 1 1 2 3 3 1...
output:
499 2996 2997 2999 2956 2992 2993 2983 2984 2985 2978 2980 2981 2968 2969 2970 2963 2965 2966 2960 2961 2962 2757 2758 2951 2733 2738 2940 2759 2761 2934 2830 2838 2931 2797 2806 2930 2927 2928 2929 2860 2861 2921 2882 2887 2919 2909 2912 2914 2873 2874 2913 2875 2881 2908 2899 2900 2901 2883 2886 2...
result:
ok count=499
Test #4:
score: 0
Accepted
time: 1ms
memory: 4176kb
input:
3000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...
output:
1 1932 1933 2901
result:
ok count=1
Test #5:
score: 0
Accepted
time: 0ms
memory: 3808kb
input:
3000 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2...
output:
1 1755 1756 2819
result:
ok count=1
Test #6:
score: -100
Wrong Answer
time: 1ms
memory: 4036kb
input:
1500 1 1 1 2 1 1 1 2 2 2 2 2 1 1 3 1 2 2 3 1 2 2 2 2 1 2 1 2 1 1 3 1 2 2 2 2 1 1 3 1 1 2 2 3 2 1 3 1 1 2 2 2 1 2 2 2 2 2 1 2 3 2 3 2 3 2 1 3 2 1 2 3 2 2 3 2 3 1 1 3 1 3 1 3 3 3 1 3 3 3 1 1 3 1 3 1 3 1 1 1 3 1 3 1 3 3 1 1 1 3 1 1 3 1 1 1 1 1 3 3 3 3 1 3 1 1 1 1 3 3 3 3 3 3 1 3 1 1 1 3 1 3 1 1 1 1 3 1...
output:
491 110 1342 1499 1371 1372 1498 1419 1420 1497 124 1326 1496 1387 1388 1495 214 1285 1494 219 1228 1493 218 1230 1492 217 1232 1491 216 1234 1490 215 1236 1489 559 621 1488 212 1238 1487 336 1102 1486 335 1104 1485 207 1240 1484 317 1138 1483 283 1210 1482 282 1213 1481 206 1242 1480 281 1215 1479 ...
result:
wrong answer the number of matches is different