Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

WHY TLE? HELP ME PLZ!

Posted by 494276076 at 2016-07-31 15:18:25 on Problem 2259
#include<iostream>
#include<map>
#include<queue>
#include<string>
#define maxn 1010

using namespace std;

map<int,int> R;
queue<int> Qt,Qp[maxn];

int main()
{
    int ss = 0;
    while (1)
    {
          int n;
          cin>>n;
          if (n == 0) break;
          for (int i = 1; i<=n; i++)
          {
              int m;
              cin>>m;
              for (int j = 0; j<m; j++)
              {
                  int x;
                  cin>>x;
                  R[x] = i;
              }
          }
          cout<<"Scenario #"<<++ss<<endl;
          while (1)
          {
                int flag = 0;
                string st;
                cin>>st;
                switch (st[0])
                {
                       case 'S':
                            flag = 1;
                            break;
                       case 'E':
                            int x;
                            cin>>x;
                            if (!Qp[R[x]].empty()) Qp[R[x]].push(x);
                            else 
                            {
                                 Qt.push(R[x]);
                                 Qp[R[x]].push(x);
                            }
                            break;
                       case 'D':
                            cout<<Qp[Qt.front()].front()<<endl;
                            Qp[Qt.front()].pop();
                            if (Qp[Qt.front()].empty())
                               Qt.pop();
                            break;
                }
                if (flag) break;
          }
          while (!Qt.empty())
                Qt.pop();
          for (int i = 0; i<maxn;i++)
          {
              queue<int> tmp;
              swap(Qp[i],tmp);
          }
          cout<<endl;
    }
    return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator