Submission #702465

# Submission time Handle Problem Language Result Execution time Memory
702465 2023-02-24T06:40:52 Z vjudge1 Lamps (JOI19_lamps) C++11
0 / 100
0 ms 212 KB
// C++ implementation of the above approach
#include <bits/stdc++.h>
using namespace std;
 
void check(int n, string s)
{
      
    // Create the modified string with
    // v[i-1] = v[i + 1] = * where s[i] = *
    char v[n];
    for(int i = 0; i < n; i++)
    {
        if (s[i] == '*')
        {
            v[i] = '*';
              
            // Checking valid index and then replacing
            // "." with "*" on the surrounding of a *
            if (i > 0 && i < n - 1)
            {
                v[i + 1] = '*';
                v[i - 1] = '*';
            }
            if (i == 0 && n != 1)
            {
                v[i + 1] = '*';
            }
            if (i == n - 1 && n != 1)
            {
                v[i - 1] = '*';
            }
        }
        else
        {
              
            // Just copying if the character is a "."
            if (v[i] != '*')
            {
                v[i] = '.';
            }
        }
    }
  
    // Creating the string with the list v
    string str(v);
     
    string word = "";
    char dl = '*';
  
    // to count the number of split strings
    int num = 0;
  
    // adding delimiter character at the end
    // of 'str'
    str = str + dl;
  
    // length of 'str'
    int l = str.size();
  
    // traversing 'str' from left to right
    vector<string> res;
    for (int i = 0; i < l; i++) {
  
        // if str[i] is not equal to the delimiter
        // character then accumulate it to 'word'
        if (str[i] != dl)
            word += str[i];
  
        else {
  
            // if 'word' is not an empty string,
            // then add this 'word' to the array
            // 'substr_list[]'
            if ((int)word.size() != 0)
                res.push_back(word);
  
            // reset 'word'
            word = "";
        }
    }
  
    int ans = 0;
    for(auto x : res)
    {
       
        // Continuing if the string length is 0
        if (x.length() == 0)
        {
            continue;
        }
  
        // Adding number of lamps for each block of "."
        ans += ceil(x.length() * 1.0 / 3);
    }
    cout << ans << "\n";
}
 
int main() {
    string s = ".....";
    int n = s.length();
    check(n, s);
    return 0;
}

Compilation message

lamp.cpp: In function 'void check(int, std::string)':
lamp.cpp:51:9: warning: unused variable 'num' [-Wunused-variable]
   51 |     int num = 0;
      |         ^~~
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -