531 - Compromise

All about problems in Volume 5. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 531 - Compromise - WA

Post by brianfry713 »

You're printing a null character at the end of each line.
Check input and AC output for thousands of problems on uDebug!
TLEorWA
New poster
Posts: 12
Joined: Sat Mar 01, 2014 12:56 pm

Re: 531 - Compromise - WA

Post by TLEorWA »

PE..PE..PE :( :evil:
help..
here is my code:

Code: Select all

thnks brianfry713.AC  :) 
Last edited by TLEorWA on Fri Jun 13, 2014 11:21 pm, edited 1 time in total.
lighted
Guru
Posts: 587
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

Why WA? I solved by DP - LCS

Post by lighted »

sorry. look to next post
Last edited by lighted on Sun Jun 15, 2014 1:42 pm, edited 5 times in total.
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 531 - Compromise - WA

Post by brianfry713 »

TLEorWA, Try the input
#
#

My AC code prints nothing, not even a blank line.
Check input and AC output for thousands of problems on uDebug!
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 531 - Compromise - WA

Post by brianfry713 »

lighted, try running your code on the sample input.
Check input and AC output for thousands of problems on uDebug!
lighted
Guru
Posts: 587
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

Re: 531 - Compromise - WA

Post by lighted »

I've changed my code. But wa. Maybe some problems with reading strings. Who can give some input tests?

Code: Select all

removed, after acc...
In one day third time i make same full mistake, not removing comments and read/write from files.

// #ifndef ONLINE_JUDGE
freopen("input.txt", "rt", stdin);
freopen("output.txt", "wt", stdout);
// #endif
Last edited by lighted on Tue Jun 17, 2014 4:26 pm, edited 2 times in total.
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 531 - Compromise - WA

Post by brianfry713 »

Don't read and write to files.
Check input and AC output for thousands of problems on uDebug!
incruator
New poster
Posts: 5
Joined: Sun Aug 31, 2014 12:32 pm

Re: 531 - Compromise PE error

Post by incruator »

I have tried every input Pleae Help .

Code: Select all

/*
Approach: Longest Common Subsequence
*/
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <memory.h>
#include <cassert>
#include<stack>
#include<queue>
#define PI 3.14159265
#define M 1000000007
#define EPS 1e-9
#define ll long long int
using namespace std;
const int N = 1000005;

int a[3005][3005];
vector<string>v;
int main()
{
//freopen("input.txt","r",stdin);
string s0;
while(getline(cin,s0))
{
if(s0.size()==0)break;
//cout<<" fuck "<<endl;
string s1[105]="",s2[105]="",s;int len1=0,len2=0;
//int c=0;
v.clear();
for(int i=0;i<s0.size();i++)
{

    if(s0=="#")break;
        if(s0[i]==' ')
        {
        //cout<<s1[len1] <<" ";
        len1++;continue;
        }
        s1[len1]+=s0[i];

    //len1++;
}
//cout<<s1[len1] <<endl;
len1++;
while(1 && s0!="#")
{
//cout<<"fuck"<<endl;
    getline(cin,s);
    if(s=="#")break;
    for(int i=0;i<s.size();i++)
    {
        if(s[i]==' ')
        {
  //      cout<<s1[len1] <<" ";
        len1++;continue;
        }
        s1[len1]+=s[i];
    }
    len1++;
}

//cout<<s1[0]<<endl;
while(1)
{
    getline(cin,s);
    if(s=="#" || s.size()==0)break;
    //if(s.size()>0)
    //cout<<"funm?"<<endl;

    for(int i=0;i<s.size();i++)
    {
      //  cout<<"fuck"<<endl;
        if(s[i]==' ')
        {
        len2++;continue;
        }
        s2[len2]+=s[i];
    }
    len2++;
}
//cout<<s1[len1-1]<<" " <<s2[len2-1]<<endl;
for(int i=0;i<len1;i++)
{
    a[i][0]=0;
}
for(int j=0;j<len2;j++)
{
    a[0][j]=0;
}
for(int i=1;i<=len1;i++)
{
    for(int j=1;j<=len2;j++)
    {
        if(s1[i-1]==s2[j-1])
        {
            a[i][j]=a[i-1][j-1]+1;
        }
        else
        {
        a[i][j]=max(a[i-1][j],a[i][j-1]);
        }
    }
}
int i=len1,j=len2;
//cout<<len1<<" k "<<len2<<endl;
while(i>0 &&& j>0)
{
  //  cout<<i<<endl;
    if(a[i][j]==a[i-1][j])i--;
    else if(a[i][j]==a[i][j-1])j--;
    else
    {
        v.push_back(s1[i-1]);
        i--;j--;
    }
}
reverse(v.begin(),v.end());
if(v.size()>=1)
{
//cout<<v[0];
for(int i=0;i<v.size();i++)
{
    cout<<v[i];
    if(i!=v.size()-1)cout<<" ";
    else
    cout<<endl;
}
}
}
return 0;
}
@briyanfry
Thanks.. Please Help.. :) :oops: :oops: :oops:
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 531 - Compromise

Post by brianfry713 »

It looks like you figured it out.
Check input and AC output for thousands of problems on uDebug!
incruator
New poster
Posts: 5
Joined: Sun Aug 31, 2014 12:32 pm

Re: 531 - Compromise

Post by incruator »

No The above code is still getting PE .. Can you tell wts wrong in that code.
Please ..
Thanks :oops: :oops:
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 531 - Compromise

Post by brianfry713 »

I saw on uhunt that you already got AC on this problem.

Try changing your input parsing. I got AC reading the input as strings, not line by line.
Check input and AC output for thousands of problems on uDebug!
Shahidul.CSE
Experienced poster
Posts: 148
Joined: Sun Jul 13, 2014 4:32 am
Location: Rangpur, Bangladesh

Re: 531 - Compromise

Post by Shahidul.CSE »

Code: Select all

Accepted ! 
Last edited by Shahidul.CSE on Sat Dec 13, 2014 5:51 am, edited 1 time in total.
Md. Shahidul Islam
Dept. of CSE at Begum Rokeya University, Rangpur, Bangladesh
UVa id: http://uhunt.felix-halim.net/id/438420
My facebook account,
Email me: shahidul.cse.brur@gmail.com
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 531 - Compromise

Post by brianfry713 »

Input:

Code: Select all

a b c d e
#
b c d e a
#
a b a a
#
a a
#
AC output:

Code: Select all

b c d e
a a
Check input and AC output for thousands of problems on uDebug!
Shahidul.CSE
Experienced poster
Posts: 148
Joined: Sun Jul 13, 2014 4:32 am
Location: Rangpur, Bangladesh

Re: 531 - Compromise

Post by Shahidul.CSE »

Thanks, now got accepted :D
Md. Shahidul Islam
Dept. of CSE at Begum Rokeya University, Rangpur, Bangladesh
UVa id: http://uhunt.felix-halim.net/id/438420
My facebook account,
Email me: shahidul.cse.brur@gmail.com
Post Reply

Return to “Volume 5 (500-599)”