Page 2 of 5

### Re: 11995 - I Can Guess the Data Structure!

Posted: Fri Mar 08, 2013 2:20 am
Altought only one test case gave incorrect output, it made me realise quite a few errors in code, so thanks for that. Got AC now.

### Re: 11995 - I Can Guess the Data Structure!

Posted: Fri Mar 22, 2013 9:28 pm

Code: Select all

``````import java.io.*;
import java.util.*;
public class Main{
public static void main(String [] args)throws IOException{
PrintWriter z = new PrintWriter(System.out);
String line;
{
Stack<Integer> s = new Stack<Integer>();
PriorityQueue<Integer> pq = new PriorityQueue<Integer>();
int temp = Integer.valueOf(line);
int a = 0,b = 0,c = 0;
while(temp-->0)
{
int cheq = Integer.valueOf(ss.nextToken());
int x = Integer.valueOf(ss.nextToken());
if(cheq==1)
{
if(a==0)
{
s.push(x);
}
if(b==0)
{
}
if(c==0)
{
}
}
else
{
if(s.size()>=1)
{
if(s.pop()!=x)
{
a = 1;
}
}
if(q.size()>=1)
{
if(q.poll()!=x)
{
b = 1;
}
}
while(pq.size()!=0)
{
}
if(ans.size()>=1)
{
if(ans.poll()!=x)
{
c = 1;
}
}
while(ans.size()!=0)
{
}
}
}
if((a==0 && b==0 && c==0)||(a==0 && b==0)||(b==0 && c==0)||(c==0 && a==0))
{
z.println("not sure");
}
else if(a==0)
{
z.println("stack");
}
else if(b==0)
{
z.println("queue");
}
else if(c==0)
{
z.println("priority queue");
}
else
{
z.println("impossible");
}
}
z.flush();
}
}
``````

### Re: 11995 - I Can Guess the Data Structure!

Posted: Sun Mar 24, 2013 10:35 am
input

Code: Select all

``````1
2 1``````
ac output

Code: Select all

``impossible``

### 11995 - I Can Guess the Data Structure!

Posted: Tue Jul 16, 2013 1:29 am
i tried it on every sample , but it gves me WA help!!

### Re: 11995 - I Can Guess the Data Structure!

Posted: Tue Jul 16, 2013 7:14 am
It looks like you figured it out.

### Re: 11995 - I Can Guess the Data Structure!

Posted: Tue Jul 16, 2013 4:33 pm
it looks like it , but still getting WA!!!

### Re: 11995 - I Can Guess the Data Structure!

Posted: Fri Jul 19, 2013 1:24 am
According to your uhunt you got AC, and you removed your code.

### Re: 11995 - I Can Guess the Data Structure!

Posted: Tue Oct 29, 2013 11:04 pm
why WA??

Code: Select all

``````#include <bits/stdc++.h>
using namespace std;
#define sc scanf
#define pf printf

int main()
{
int t;
while(sc("%d", &t)!=EOF)
{

stack<int> st;
queue<int> qu;
priority_queue<int> pq;
int sf=1,qf=1,pf=1,f1=0,f2=0;
vector<int> v1;
vector<int> v2;
int a, b;
int stt,qut,pqt;
for(int i=0;i<t;i++)
{
if(a==1){
st.push(b);
qu.push(b);
pq.push(b);
f1=1;
}

if(a==2){

if(sf && !st.empty()){
stt=st.top();
st.pop();
if(stt!=b){
sf=0;
}
f2=1;
}

if(qf && !qu.empty()){
qut=qu.front();
qu.pop();
if(qut!=b){
qf=0;
}
f2=1;
}

if(pf && !pq.empty()){
pqt=pq.top();
pq.pop();
if(pqt!=b){
pf=0;
}
f2=1;
}
}
}
if(sf+qf+pf > 1 && f1 && f2 ) puts("not sure");
else if(sf+qf+pf==1 && f1 && f2){
if(sf==1) puts("stack");
if(qf==1) puts("queue");
if(pf==1) puts("priority queue");
}
else puts("impossible");

}
return 0;

}

char r;
bool start=false,neg=false;
long long int ret=0;
while(true){
r=getchar();
if((r-'0'<0 || r-'0'>9) && r!='-' && !start){
continue;
}
if((r-'0'<0 || r-'0'>9) && r!='-' && start){
break;
}
if(start)ret*=10;
start=true;
if(r=='-')neg=true;
else ret+=r-'0';
}
if(!neg)
return ret;
else
return -ret;
}

``````

### Re: 11995 - I Can Guess the Data Structure!

Posted: Thu Oct 31, 2013 10:55 pm
Input:

Code: Select all

``````1
1 1``````
Output should be not sure

### Re: 11995 - I Can Guess the Data Structure!

Posted: Fri Nov 01, 2013 9:56 am
Que puedo hacer, para no Obtener Time Limit

import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Stack;

/**
*
* @author OSCAR
*/
public class Main {
public static void main(String[] args) throws IOException {
Stack<Integer> pila=new Stack<Integer>();
PriorityQueue<Integer> colap = new PriorityQueue<Integer>(1001, Collections.reverseOrder());

int arreglopila[]=new int[1001], original[]=new int[1001], arreglocola[]=new int[1001], arreglocolap[]=new int[100], banderas[]=new int[5];

banderas[0]=0;
banderas[1]=0;
banderas[2]=0;
for (int i=0; i<numero; i++){
if (opcion==1){
pila.push(valor);
}
else{
banderas[0]=0;
else
banderas[0]=1;

banderas[1]=0;
else
banderas[1]=1;

banderas[2]=0;
else
banderas[2]=1;

}
}
for (int i=0; i<3; i++){
if (banderas==0)
}
System.out.println("impossible");
else{
System.out.println("not sure");
else{
if (banderas[0]==0)
System.out.println("stack");
if (banderas[1]==0)
System.out.println("queue");
if (banderas[2]==0)
System.out.println("priority queue");
}
}
}
}
}

### Re: 11995 - I Can Guess the Data Structure!

Posted: Tue Nov 05, 2013 9:49 pm
Try using BufferedWriter

### Re: 11995 - I Can Guess the Data Structure!

Posted: Wed Nov 13, 2013 1:50 pm
why wa this time??

Code: Select all

``````#include <bits/stdc++.h>
using namespace std;
#define sc scanf
#define pf printf

int main()
{
int t;
while(sc("%d", &t)!=EOF)
{

stack<int> st;
queue<int> qu;
priority_queue<int> pq;
int sf=1,qf=1,pf=1,f1=0,f2=0,x=0,y=0,z=0, c1=0, c2=0;
map<int,int> mp1, mp2;
int em=0;
int a, b;
int stt,qut,pqt;
for(int i=0;i<t;i++)
{
if(a==1){
st.push(b);
qu.push(b);
pq.push(b);
mp1[b]++;
f1=1;
c1++;
}

if(a==2){
c2++;
if(!mp1[b]) em=1;
if(sf && !st.empty()){
stt=st.top();
st.pop();
if(stt!=b){
sf=0;
}
if(sf){
f2=1;
x=1;
}
}

if(qf && !qu.empty()){
qut=qu.front();
qu.pop();
if(qut!=b){
qf=0;
}
if(qf){
f2=1;
y=1;
}
}

if(pf && !pq.empty()){
pqt=pq.top();
pq.pop();
if(pqt!=b){
pf=0;
}
if(pf){
f2=1;
z=1;
}
}
}
}
//cout<<f1<<" "<<f2<<" "<<x<<" "<<y<<" "<<z<<" ";
if(em) puts("impossible");
else if(sf+qf+pf==1 && f1 && f2){
if(sf==1) puts("stack");
if(qf==1) puts("queue");
if(pf==1) puts("priority queue");
}
else {
if(sf+qf+pf==0) puts("impossible");
else puts("not sure");
}
}
return 0;

}

char r;
bool start=false,neg=false;
long long int ret=0;
while(true){
r=getchar();
if((r-'0'<0 || r-'0'>9) && r!='-' && !start){
continue;
}
if((r-'0'<0 || r-'0'>9) && r!='-' && start){
break;
}
if(start)ret*=10;
start=true;
if(r=='-')neg=true;
else ret+=r-'0';
}
if(!neg)
return ret;
else
return -ret;
}

``````

### Re: 11995 - I Can Guess the Data Structure!

Posted: Thu Nov 14, 2013 10:36 pm
Your code is unnecessarily complex. You can just simulate the three data structures. You don't need a map and as many extra variables as you have.

### Re: 11995 - I Can Guess the Data Structure!

Posted: Sun Dec 01, 2013 10:19 pm
Getting a TLE. Thoughts? I can short circuit if the "impossible" case is reached... but that shouldn't be too big of an optimization.

Accepted.

Wow..... Didn't think that would make that much of a difference...

http://stackoverflow.com/questions/6911 ... ring-split

Thanks Brian!

### Re: 11995 - I Can Guess the Data Structure!

Posted: Wed Dec 04, 2013 12:14 am
Try using a StringTokenizer instead of split()